Question: 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

Answer: 
`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.
I've started to get this error with **Visual studio 2022**.

My project is set to AnyCPU, but some dll is compiled to x86, and I was unable to change it because I don't have the source. In previous versions of VS the project works.

I realized that in previous versions of visual studio (vs 2019 for example) the default IIS is to run on x86 (after all it is an x86 process too) as you can see here:
[![enter image description here](https://i.stack.imgur.com/7PicH.png)](https://i.stack.imgur.com/7PicH.png)

but in VS 2022 this option is checked by default.

**Solutions:**

The **first solution** is to *uncheck the option* "Use the 64 bit version of IIS Express for web sites and projects" in Options -> Projects and Solutions.

But this will change the IIS Express version for all projects.

The **second solution** is to change IIS Express only for that solution (I prefer that because most of my projects don't have specific compiled dll's)

1- Go to solution properties -> Web, in Servers section change bitness to x86:
[![enter image description here](https://i.stack.imgur.com/z2UgP.png)](https://i.stack.imgur.com/z2UgP.png)

**Conclusion**

The best solution is to have all dll compiled to the same platform (x86, x64, AnyCPU, etc.), but if like me you were unable to do it, this will solve for you.