#SharePointProblems | Koskila.net

Solutions are worthless unless shared! Antti K. Koskela's Personal Professional Blog

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

koskila
Reading Time 4 min
Word Count 570 words
Comments 31 comments
Rating 4.7 (16 votes)
View

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.

Problem

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.

Reason

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:
    IIS Express 64-bit version - how to fix the "Could not load file or assembly..." error
    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 :)

Comments

Interactive comments not implemented yet. Showing legacy comments migrated from WordPress.
Kiet Chi Luu
2019-08-21 09:06:17)
Hi there, I do have a quick question. I have a 32-bit web app. I had to incorporate a 64-bit Oracle.DataAccess.dll. I checked the "Use the 64 bit IIS Express for websites and projects" in order to get it to build and run on my local machine. However when I deployed it to my test webserver, I got the incorrect format error. From what I read, I understand that an application can not run both 32 bit and 64 bit dlls in the same project. My application does use both bit types. I was wondering how the application is able to run on my local machine, but not when it is deployed. My test webserver uses IIS7. Thank you for any replies, Kiet
2019-08-21 14:45:01
Hi Kiet, Hmm - do you get the error about the format for the Oracle assembly, or the ones your app compiles to? For the most part, I'd just switch my app to compile to 64 bit as well, but do you have a reason not to? Additionally, I guess you could do some interesting configuration like the one in this link to see if you can load both architectures in the same web app: https://blogs.msdn.microsoft.com/rakkimk/2007/11/03/iis7-running-32-bit-and-64-bit-asp-net-versions-at-the-same-time-on-different-worker-processes/
Mike Hagesfeld
2019-09-20 15:26:52)
Thank you!! VS2019 encountered this issue after it worked in VS2017, totally this fixed it, thanks!
2019-09-21 11:16:55
Happy to hear it helped, Mike! :)
Nigus
2019-11-26 16:19:46)
Hi there, I still get the error after deploying my web api although i changed the iis to 64 bit publishing. I am deploying to apache mono running on ubuntu server. and publishing as ftp. Could it be another issue. It works on localhost. but the problem comes after deploying. Thanks
2019-11-28 10:57:39
Hi Nigus, Yikes - yeah, that could be a bit of a different case. Still, it's worth checking the architecture of your app and your dependencies. Which version (and bitness) of Mono are you running?
Richard Cimbalo
2020-02-18 16:35:41)
Thank you for this. Another developer started using 64 bit database drivers and changed dependencies for the whole solution.
2020-02-20 00:27:52
Happy to hear it helped! Never a dull moment, huh? Would love to see people communicating with their teams about decisions like this... It sounds like a Pull Request turned down to me! 😉
Vikramraj
2020-03-04 14:48:46)
yes its works
Jeet
2020-03-05 13:30:02)
Hi, What if it is a window application and the dll which is throwing this error is one project's assembly of the same solution and at customer end only.
2020-03-05 13:49:46
Hi Jeet, Do you get the error about incorrect format, or just a generic "could not load file or assembly"? You could check whether the files are blocked, too deep into the folder structure, and whether the customer still has 32b operating systems (hey, half of the government agencies have just upgraded to Windows XP, so...) Some more info here: How to resolve issues when loading DLLs in PowerShell? (some applies to your case as well)
Prashant Sedhain
2020-03-25 18:12:54)
Thanks a lot!!!
2020-03-31 14:06:17
Happy it was helpful! :)
priya
2021-01-26 08:07:28)
above solution is worked thank u
2021-01-26 09:57:54
Thanks for your comment, priya - happy to hear it was helpful! :)
Tim Bunting
2021-03-01 19:18:50)
Worked for me. Great. Thanks
Antti K. Koskela
2021-03-02 10:22:40
Thanks, Tim. Awesome to hear it helped!
becky
2022-01-11 22:13:19)
Thank you! I was fighting with this all day yesterday, and this seems to have fixed the issue.
Antti K. Koskela
2022-01-12 18:11:40
Hi Becky, happy to hear it worked! 😁
Lukmanul Hakeem T
2022-03-22 12:47:57)
Thanks a lot...
2022-03-22 16:17:57
Happy to be of help!
2022-07-25 13:59:38)
Hi , greeting trying to solve this problem but useless
  • Error while loading code module: ‘TestLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’. Details: Could not load file or assembly 'TestLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
t TestLib is my custom assembly & I'm using VS2010 Pls.help
Antti K. Koskela
2022-08-05 16:40:58
Hi mate, Hmm, you don't give me much to work on. 🤔 What kind of a solution/app are you trying to reference/load/import the module from? Is the file physically where it's supposed to be? Is this thrown during development or in production? What's the technical reasoning behind using VS2010 (this makes me think you're using some pretty old-fashioned or slightly more eccentric technology)?
Richard
2022-08-21 12:42:46)
You say open VS Studio to fix could not load file assembly problem, but how do I open VS Studio? Where is it. Do I even have it on my machine? How can I tell?
2022-08-22 12:32:24
Hi Richard, This solution only applies to when you're deploying your code from Visual Studio, like said in the article: 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. So if you don't have Visual Studio installed, this fix probably does not apply to you 😅
prajakta sutar
2024-01-31 13:53:47)
Hey, I still get the error for pdfNet.dll on localhost. I'm using vs2019. Could it be another issue?
Antti K. Koskela
2024-03-26 09:45:14
Heya and thanks for your question! The beginning of the error (the part that doesn't talk about "format") is generic enough it could be any of many issues. If you don't have that in the error message, it's a good idea to also make sure the DLL is in fact available wherever you're trying to reference it from (for example, that it's copied to bin folder if debugging). If you do have the error about format, if you're deploying to a local IIS instance, you might want to check that you have this value as "False" if you're building a 64-bit application (as you typically are):
Sakeer Hussain
2024-02-24 07:36:49)
Well explained, Thank you for posting a solution.
Antti K. Koskela
2024-03-25 19:20:22
Thanks for the feedback, appreciate it!
Whitewater Magpie Ltd.
© 2025
Static Site Generation timestamp: 2025-08-26T05:15:50Z