Could not load file or assembly 'xxx' or one of its dependencies

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

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
Exception Details: System.BadImageFormatException: Could not load file or assembly 'xxx' or one of its dependencies. An attempt was made to load a program with an incorrect format.

 

There could be a number of reasons for the above error. I'm listing down some of them below -

1. You have both 32 bit and 64 bit binaries in your bin folder

2. Your publish settings are not in-sync with your build settings. More here

3. 32 bit dlls are disabled by default in IIS. So, if required, try enabling that

4. Depending on if you have 64 bit dlls then 64 bit version should be enabled in IIS express (Obviously, if this is applicable to you)

 Solutions:

1. If your situation is point #1 and you are running your solution out of VS then change your solution platform to x86 because VS is a 32 bit app. Refer to image 1 below.

 2. Otherwise, it's just a matter of configuration. And, links are provided in the above points.

Image 1:

 

Recommended reading:

1. https://blogs.msdn.microsoft.com/ricom/2009/06/10/visual-studio-why-is-there-no-64-bit-version-yet/

2. https://www.hanselman.com/blog/BackToBasics32bitAnd64bitConfusionAroundX86AndX64AndTheNETFrameworkAndCLR.aspx

3. https://blogs.msdn.microsoft.com/ricom/2015/12/29/revisiting-64-bit-ness-in-visual-studio-and-elsewhere/

4. https://docs.microsoft.com/en-us/dotnet/framework/64-bit-apps

Add comment