Does your web site uses the DefaultAppPool? If so, try setting the application pool of your web site to ASP .Net v4.0, Or if you are using a customized app pool, verify that it is running .net framework 4.0
The BadImageFormatException
is raised when the assembly file can be found, but is not a proper assembly, or is corrupted. For instance, if you FTP'ed the files to the server and the transfer was interrupted, the DLL file may have been transferred only partially, causing this error to happen.
On 64 bit vs 32 bit: when you use P/Invoke or COM Interop, some blogger reports that switching to a specific target compilation may help your situation. This means: if you interface with a 32 bit dll, make sure that you compile for x86
, forcing it to run under WoW32, otherwise you'll receive this exception. This fix is confirmed here and here.
Alternatively, you can set your whole system to default 32-bit by running the command:
Ldr64.exe setwow
from the Framework64
directory.
A common solution is to rebuild the file, or to at least re-publish it.