An attempt was made to load a program with an incorrect format
Could not load file or assembly 'NameOfAssemblyGoesHere' or one of its dependencies. An attempt was made to load a program with an incorrect format.
This message being spewed-forth by an asp.net application means that the DLL concerned has been compiled as a specific "bitness", but one that doesn't match that which IIS is running at. The most usual reason for this is an assembly marked as "x86" deployed to an "x64" server. If the assembly doesn't P/Invoke out to any 32-bit DLLs, change the platform target to "AnyCpu".
As far as the .net framework is concerned, the x86/x64 categorisation is only used as an indicator of requirements, thus if no P/Invoke is going on it's not needed, as the JIT compiler takes the assembly and JIT compiles it to the relevant instruction set at runtime anyway.

Another workaround is to set IIS in compatibility mode for 32 bits.
That worked for me.
1.
Open a command prompt and navigate to the %systemdrive%\Inetpub\AdminScripts directory.
2.
Type the following command:
cscript.exe adsutil.vbs set W3SVC/AppPools/Enable32BitAppOnWin64 “true”
3.
Press ENTER.
Source:
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/13f991a5-45eb-496c-8618-2179c3753bb0.mspx?mfr=true
The "true" parameter didn't work for me. I used the following statement.
cscript.exe adsutil.vbs set W3SVC/AppPools/Enable32BitAppOnWin64 1
It might happen not only because of this. I figured out it happened for my WCF project in case I added string
in my web.config inside service configuration section. As I removed it, everything works fine.
Basically .net sucks. that explains how all these stupidity exists just to make developers life harder. for no good reason.
Oh, lool, a troll. No language or framework is perfect, and .net certainly isn't. It's without a doubt better than VB6/Java/Classic ASP and all the others of that era. Troll somewhere else, please.
Thanks for the post - worked a charm!
I'm using Visual Studio 2010 deploying on Windows Server 2008 with IIS 7 and got around this problem by doing the following:
- Open IIS snap-in
- Click on "Application Pools"
- In the center pane click on the application pool used by your site
- In the right-hand pane click "Advanced Settings..."
- In the dialog set "Enable 32-bit applications" to "true"
- Click "OK"
Hope this helps.