Visual Studio logo

Fixing the “Could not load file or assembly or one of its dependencies” error

This post was most recently updated on April 18th, 2024.

3 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 an error somewhat like the above when deploying to IIS or when opening your website after the deployment.

This applies to your local development environment.

AI-powered summary: Troubleshooting .NET Assembly Loading Issues

This article provides a guide to resolving the “.NET assembly loading error” encountered during IIS deployment. The error typically arises from architecture mismatches, specifically when a 64-bit application is deployed to a 32-bit IIS Express. The solution involves configuring IIS to run in 64-bit mode, which aligns with the application’s architecture. The process is outlined in four simple steps, ensuring a smooth deployment in a 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 in the right direction. “An attempt was made to load a program with an incorrect format.” That means that the assembly, which was to be loaded, was in an unexpected format. The format, in this case, refers most likely to the 64-bit build of an application being deployed to IIS, which is being run in 32-bits.

Why do I think that’s the case? Well, see – by default, Visual Studio uses a 32-bit version of IIS Express (Internet Information Services Express – the free lightweight web server that ships with some Windows versions and are useful for local development with Visual Studio) for your deployments. And if you’re building your solution in x64, running it in 32-bit IIS Express won’t work.

In case you know what you’re doing, it’s safe and easy to change this, though.

In my case, I was indeed building a 64-bit application. Therefore I also had to change the IIS to run in a 64-bit version. That’s luckily quite easy!

Solution: Change the IIS Express to run in 64b

I’ll explain below, how to do this in 4 simple steps. Like, really simple.

Time needed: 2 minutes

How to change IIS Express to run in 64-bit mode?

  1. You’ll need to enable 64-bit IIS Express from VS settings

    This is an easy, one-click configuration change, but it is hidden quite deep in the Options. First, open up your Visual Studio.

  2. Navigate to Visual Studio – Tools – Options – Projects and Solutions – Web Projects

    Alternatively, use the search for and write “64 bit”.

  3. Select “Use the 64-bit version of IIS Express for websites and projects”

    This’ll look something like in the picture below:
    How to enable the 64-bit version of IIS Express in Visual Studio 2017
    IIS Express 64-bit version – how to fix the “Could not load file or assembly…” -error

  4. Hit “OK” to save your changes.

    That’s it. 4 (or really more like 3) simple steps!

And you should be golden!

Let me know in the comments -section below whether it worked or not. It sure did for me :)

4.7 16 votes
Article Rating
Notify of

most voted
newest oldest
Inline Feedbacks
View all comments