This post was most recently updated on February 9th, 2021.2 min read.
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 (Internet Information Services Express – the free lightweight web server that ships with some Windows versions and is useful for local development with Visual Studio) 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 indeed 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
See the steps below.
Time needed: 2 minutes.
How to change IIS Express to run in 64-bit mode?
- 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
Alternatively, use the search for and write “64 bit”.
- 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. It sure did for me :)
- Experiment: DateTime formats - April 21, 2021
- How to fix “LinkedAuthorizationFailed” when deploying an Azure Logic App? - April 15, 2021
- How to fix a build configuration that’s not available as a build directive in Visual Studio? - April 14, 2021