Saturday, December 22, 2007

64 Bit Windows with C# Express .Net and 32 Bit DLL's

An architecture change is always welcome and the 64 Bit world presents new and options for memory management and the like but there is certainly a price to pay for this shift. So far my personal experience with the 64 bit world has been one of mixed emotions, many hours of things not working, spending time researching on the net and looking for obtuse answers that sort of solve our problems.

The latest one is trying to develop using C# Express 2008 on Windows XP 64 Bit Edition and then using interoperability with a 32 Bit DLL - OpenAl. For some reason the compiler doesn't realise that the 32 Bit DLL is just that, 32 Bits. By default any .Net application developed will target the platform called "Any CPU" as opposed to a specific architecture. This is cool if your not using native DLL's but is a bit of a pain when you do. You will know that you are getting this problem when you start seeing System.BadImageFormatException popping up. It means that your application is trying to cross the Bit boundary - apparently our gracious OS is a separatist?

Any way there seems to be a saving grace, you can do development on a 64 Bit OS and set C# Express to specifically target your application to x86, it's just not obvious. Targeting x86 will mean that your application will still run on a 64 Bit OS but will use WoW (Windows on Windows, which is a compatibility layer to backwards support 32 Bit applications) so you won't get the native use of those 64 Bit Int's but you will be able to use your 32 Bit DLL's.

To setup your application to do this you need to
  1. G in to the menu option Tools>Options and the in the dialog box tick the box in the bottom right corner to "Show all settings"
  2. Once the settings expand go to "Projects and Settings" expand it and click on "General"
  3. Check the option which is called "Show advanced build configurations", then close the dialog box
  4. Now if you right click on the solution explorer, chose properties
  5. Goto "Configuration Properties", now you should be able to see the platform drop down. This will probably have only "Any CPU" selected; if so click on "Configuration Manager"
  6. Chose the option "New" under the "Active Solution Platform" drop down box
  7. Chose the new platform of x86 and copy your settings from "Any CPU"
  8. Then just make sure that your projects in your solution refer to x86 as the platform rather that "Any CPU"


Psy said...

Thanks a lot, solved the problem

Anonymous said...

Now Direct3D works fine in VB.NET thanks!

I wasn't able to get Direct3D to render properly on my main form until I followed the instructions here and now it's working.

Anonymous said...

Many many thanks for your post. I couldn't find any clear instructions on how to fix it anywhere. Now I can continue with my C# assignments.

Anonymous said...

You are the best person in the world!

Krzyl2 said...


Anonymous said...

Thanks a lot

Anonymous said...

Thanks a bunch! This fixes an issue we had with the JET database driver.

Sebastian said...


none said...

Thanks. This was a big help

Anonymous said...

Thanks. This helped a lot