This code works perfect fine on my winxp32.

When I try to compile it on my vista64 however I get an unhandled exception.

is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)
Make sure the file is a valid assembly.
Make sure you have supplied the correct file path for the assembly.

Any class I try to use from that assembly causes it to throw.
Am I supposed to compile my project some specific way? I've already tried building with the x86 configuration.

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX.Direct3D;

namespace WindowsFormsApplication1
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
    public class Form1 : Form
    {
        public Form1()
        {
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Text = "Form1";
            Device d; //If I comment out this whole line then it works perfectly
        }
    }
}