XNA Framework on 64 bit Windows

Originally posted to Shawn Hargreaves Blog on MSDN, Monday, February 25, 2008

Ever seen this error message?

Could not load file or assembly 'Microsoft.Xna.Framework, Version=2.0.0.0, Culture=neutral, PublicKeyToken=6d5c3888ef60e27d' or one of its dependencies. An attempt was made to load a program with an incorrect format.

This is right up there in the pantheon of unhelpfulness. What does "incorrect format" mean, anyway? Has my framework installation somehow been corrupted?

Nine times out of ten, what the exception really meant to say was:

Could not load 32 bit assembly 'Microsoft.Xna.Framework' into a 64 bit process. Your game project is set to 'Any CPU' platform, when it should specify 'x86'.

 

Why does this occur?

64 bit Windows can run both 32 and 64 bit programs. Running a 32 bit program on a 64 bit operating system might sound slow, but actually isn't, because this uses a special CPU mode as opposed to slow emulation.

You can't mix and match, though. A 32 bit program can only load 32 bit libraries, and likewise 64 bit programs can only load 64 bit libs.

In .NET, you have three options:

But here's the thing: the XNA Framework is a 32 bit (x86) assembly. We do not provide a 64 bit version.

If you make an XNA Framework game using the 'Any CPU' configuration, then run this on 64 bit Windows, look what happens:

 

Why doesn't this happen all the time?

If you use our standard project templates, these are set up to target the 'x86' platform, not 'Any CPU'. This produces a 32 bit program, which will always run in 32 bit mode, even on 64 bit Windows.

The error only occurs if you create a project using some other template, which defaults to 'Any CPU', and then manually reference the XNA Framework. This often happens when people try to use the XNA Framework inside a WinForms application, for instance.

 

How do I fix it?

In your Visual Studio toolbar, there should be a combo box saying 'Any CPU'.

If you are using C# Express, this toolbar entry may be grayed out. To enable it, go to 'Tools / Options', check 'Show all settings', select the 'Projects and Solutions' tab, and check the 'Show advanced build configurations' box.

Pull down the 'Any CPU' toolbar combo, and choose 'Configuration Manager'. Open the 'Active solution platform' combo, choose '<New...>', and create an 'x86' configuration.

Blog index   -   Back to my homepage