Could not load file or assembly exception
Any thoughts on what might be causing this exception?
I have a webservice proj, when i load the link i get
Could not load file or assembly 'Interop.DIB' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Exception Details: System.BadImageFormatException: Could not load file or assembly 'Interop.DIB' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Inner exceptions:
[BadImageFormatException: Could not load file or assembly 'Interop.DIB' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
[ConfigurationErrorsException: Could not load file or assembly 'Interop.DIB' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
[HttpException (0x80004005): Could not load file or assembly 'Interop.DIB' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
Version Information:
Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
Solution 1:
Ok the answer is Got to Start->Run->type inetmgr and on the left application pools, select DefaultAppPool and the virtual directory name of the app and for both make sure to enable 32 -bit applications to true, am using IIS7.0 and windows 7 64-bit.
Solution 2:
BadImageFormatException
usually means 64 vs 32 bit conflict. One of the assemblies is set to a specific platform i.e. 64 bit or 32 bit while the other is set or defaults to a different one. Check if both assemblies are for the same platform, preferably "Any CPU". In other words it could be that a 64 bit assembly is trying to load 32 bit one or vice versa.
This also applies if you're calling a COM or a DLL which is compiled for different platform, for example you call 32 bit COM/DLL from an assembly on a 64 bit system where assembly's platform would default to x64. In this case adjust your assembly's platform to match.
To change platform go to project Properties -> Build -> Platform.
Solution 3:
I had this issue, when trying to use 64-bit .dlls in my ASP.Net project, in Visual Studio 2013.
The solution was to click on Tools\Options, and tick this box: