This post was most recently updated on January 17th, 2021.Reading Time: 2 minutes.
This post describes how to fix the “Could not load file or assembly ‘[assemblyname]’ or one of its dependencies. An attempt was made to load a program with an incorrect format.” error.
The solution described in this post shows you how to resolve the issue when you’re deploying from Visual Studio, but get the error “Could not load file or assembly or one of its dependencies” when deploying to IIS or when opening your website after the deployment.
This applies to your local development environment.
Especially while installing a new dev machine, and building your project for the first time, you may end up getting the following exception:
Could not load file or assembly ‘[assemblyname]’ or one of its dependencies. An attempt was made to load a program with an incorrect format.
No fear, though, as this is usually easily fixed. In quite a few cases, it’s simply a mismatch between architectures and easily changed.
The latter part of the error message should point you
By default, Visual Studio uses 32-bit version of IIS Express for your deployments. In case you know what you’re doing, it’s safe and easy to change this, though. If you’re building your solution in x64, running it in 32-bit IIS Express won’t work.
In my case, I was building a 64-bit application. Therefore I also had to change the IIS to run in
Solution: Change the IIS Express to run in 64b
Okay – see the steps below.
Time needed: 1 minute.
How to change IIS Express to run in 64-bit
- You’ll need to enable 64-bit IIS Express from VS settings
This is easy, one-click configuration change, but it is hidden quite deep in the Options.
- Navigate to Visual Studio – Tools – Options – Projects and Solutions – Web Projects
- Select “Use the 64 bit version of IIS Express for web sites and projects”
IIS Express 64-bit version – how to fix the “Could not load file or assembly…” -error
- Hit “OK” to save your changes.
And you should be golden!
Let me know whether it worked or not.
- How to recover the private key of a (.pfx) certificate? - January 20, 2021
- How to fix “System.IO.FileSystem: Could not find a part of the path \AppData\Local\AzureFunctionsTools\Releases\3.17.0\workers. Value cannot be null. (Parameter ‘provider’)” when running Azure Functions locally? - January 12, 2021
- How to nuke the Identity Cache in Visual Studio? - January 11, 2021