This post was most recently updated on March 5th, 2020.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.
How to change IIS Express to run in 64-bit
- You’ll need to enable 64-bit IIS Express from VS settings:
- Navigate to Visual Studio – Tools – Options – Projects and Solutions – Web Projects
- Select “Use the
64 bitversion of IIS Express for web sites and projects”
- Hit “OK” to save your changes.
See the screenshot below:
And you should be golden!
Let me know whether it worked or not.
- (Literally) Breaking: Changes to app authentication on SharePoint! 😵 - September 21, 2020
- How to remove your account as a guest in another Azure AD tenant? - September 16, 2020
- Is Lifetime Spotify Premium a scam? - September 10, 2020