Visual Studio 2010: how to force ASP.NET website to use x86 instead of "Any CPU"?

Jeroen Wiert Pluimers picture Jeroen Wiert Pluimers · Apr 14, 2011 · Viewed 11.6k times · Source

When using SharePoint DLLs (which are x86 only) from a non-ASP.NET app, you can set the "Platform target" to x86 (instead of "Any CPU") so both Visual Studio 2010 and the app load the SharePoint assemblies fine.

However, when developing ASP.NET applications on an x64 development system, you get this dreaded error message when building the web-site:

Could not load file or assembly 'Microsoft.SharePoint.Search' or one of its dependencies. An attempt was made to load a program with an incorrect format.

This is because ASP.NET by default is "Any CPU" when building in Visual Studio 2010.

How can I change that?

I tried the property pages for the web-site, the web.config, but to no avail.

Note: this is for the development system. I know that for the server system, I can change the application pool to force loading of 32-bit x86 by setting "Enable 32-Bit Applications" to "True" in the "Application Pool Defaults".

Answer

Aristos picture Aristos · Apr 14, 2011

You can set custom compiler option on web.config on the <compilers>

compilerOptions="/platform:string"

where string can be found here: http://msdn.microsoft.com/en-us/library/zekwfyz4(VS.80).aspx