Could not load file or assembly or one of its dependencies

928,074

Solution 1

  1. Check if you are referencing an assembly which in turn referencing an old version of unity. For example let's say you have an assembly called ServiceLocator.dll which needs an old version of Unity assembly, now when you reference the ServiceLocator you should provide it with the old version of Unity, and that makes the problem.

  2. May be the output folder where all projects build their assemblies, has an old version of unity.

You can use FusLogVw to find out who is loading the old assemblies, just define a path for the log, and run your solution, then check (in FusLogvw) the first line where the Unity assembly is loaded, double click it and see the calling assembly, and here you go.

Solution 2

Open IIS Manager

Select Application Pools

then select the pool you are using

go to advanced settings (at right side)

Change the flag of Enable 32-bit application false to true.

Solution 3

For me, none of the other solutions worked (including the clean/rebuild strategy). I found another workaround solution which is to close and re-open Visual Studio.

I guess this forces Visual Studio to re-load the solution and all the projects, rechecking the dependencies in the process.

Solution 4

Try to clean Debug and Release folders in your solution. Then remove and add unity again.

Solution 5

At 99% the Could not load file or assembly or one of its dependencies problem is caused by dependencies! I suggest you follow this steps:

  1. Download Dependency Walker from http://www.dependencywalker.com/

  2. Launch Dependency Walker and open the dll (in my case NativeInterfaces.dll)

  3. You can see one or more dll with the error in red Error opening file...

  1. It means that this dll is missing in your system; in my case the dll name is MSVCR71.DLL

  2. You can download missings dll from google and copy in right path (in my case c:\windows\system32)

  3. At this point, you must register the new dll in the GAC (Global Assembly Cache): open a DOS terminal and write:

     cd \Windows\System32
     regsvr32 /i msvcr71.dll
    
  4. Restart your application

Share:
928,074

Related videos on Youtube

ronag
Author by

ronag

Master of Science (M.Sc.), Software Engineering and Technology at Chalmers University of Technology. I wrote most of CasparCG 2.0 Server, an open-source video- and graphics playout server used by the Swedish Broadcasting Corporation 24/4 for all regional and national broadcasts in Sweden. Big fan of the ffmpeg project.

Updated on February 19, 2022

Comments

  • ronag
    ronag over 2 years

    I'm having another of these "Could not load file or assembly or one of its dependencies" problems.

    Additional information: Could not load file or assembly 'Microsoft.Practices.Unity, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

    I have no idea what is causing this or how I could debug it to find the cause.

    I've done a search in my solution catalogs .csproj files, and every where I have Unity I have:

    Reference Include="Microsoft.Practices.Unity, Version=2.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"

    Can't find any reference anywhere which goes against 1.2.0.0 in any of my projects.

    Any ideas how I should go about solving this?

    • decyclone
      decyclone over 13 years
      Could any of your referenced assemblies be using some stuff in old Unity library?
    • ronag
      ronag over 13 years
      Probably... but how can I find which assemblies? I have a lot of projects in my solution and a lot of potential suspects... trial and error bruteforce seems a bit hopeless...
    • decyclone
      decyclone over 13 years
      You only have to look into the referenced assemblies in the project for which you get this error.
    • user1703401
      user1703401 over 13 years
      It's not the assembly reference, you reference version 2.0. But at runtime, the CLR is finding 1.2, an old version. If you don't see that old DLL in your build directory then use Fuslogvw.exe to find out how the CLR found this old copy.
    • coggicc
      coggicc almost 9 years
      Look at your project's bin folder and see if your project's dll has a conflict in it's name. Just delete that one and then Rebuild your solution. That worked for me.
    • Matt
      Matt about 8 years
    • Paul McCarthy
      Paul McCarthy about 7 years
      "or one of its dependencies" is the part that really annoys me. If it can't load "one of its dependencies" the error should say which "one of its dependencies" can't be loaded. The current form is useless, it might as well say can't load thinggy
  • Scott Rippey
    Scott Rippey over 12 years
    This issue can be caused by a lot of things ... your solution solved my problems, and might solve others' as well.
  • Martin
    Martin over 10 years
    IIS -> select each ApplicationPool -> Basic Settings -> check if the latest framework is selected under the ".NET Framework version" dropdown
  • botenvouwer
    botenvouwer over 10 years
    @ScottRippey This worked for me to. I first deleted all .pdb files and then reloaded my project and rebuild it.
  • Stiger
    Stiger almost 10 years
    Where's the log file of FuseLogVw
  • eran otzap
    eran otzap over 9 years
    You can also right click your project in VS . and remove the prefer 32 bit checkmark
  • RedGreenCode
    RedGreenCode over 9 years
    To avoid having to find the log file, you can specify a custom log path: Settings, check the Enable custom log path checkbox, enter a custom log path, refresh.
  • Muflix
    Muflix almost 9 years
    I dont have "Solution -> Package" in my VS2010 project
  • Dhir Pratap
    Dhir Pratap over 7 years
    Dependency walker is great, but copying random DLLs from the internet to Windows is ... less great. It's better to try to find the installer that provides those dlls.
  • meekash55
    meekash55 over 7 years
    Thanks. It worked. Well it was already True in my case , just for try. I made it False and it worked.
  • Draex_
    Draex_ almost 7 years
    Does not work with Community editions of Visual Studio
  • Mykola Tarasyuk
    Mykola Tarasyuk almost 7 years
    I believe there should be another issue, not related to Visual Studio edition. I tested the extension on VS 2017 and VS 2015 Community editions. Actually it was developed by means of VS 2017 Community edition.
  • Draex_
    Draex_ almost 7 years
    Aha. Do you have any other extensions installed? This page says that DGML is not supported in VS Community: msdn.microsoft.com/en-us/library/hh871439.aspx#VersionSuppor‌​t
  • Mykola Tarasyuk
    Mykola Tarasyuk over 6 years
    There are no architecture tools in the Community edition but the DGML editor itself it available. You can install it selecting "Install DGML editor" under "Individual Components" -> "Code Tools" via Visual Studio Installer -> Modify
  • samneric
    samneric over 6 years
    This worked for me although it was web.config, not app.config
  • Bonez024
    Bonez024 over 6 years
    Spent so long on this and I cannot believe this was the answer. It's usually good go-to solution when you're seeing some odd behavior within VS. Thank you.
  • cheriejw
    cheriejw about 6 years
    I got a few files (API-MS-WIN-CORE-KERNEL32-PRIVATE-L1-1-1.DLL) not found and led me to this stackoverflow question. Basically keep in mind could be looking at false positive for some files, link provides more detail.
  • Iannazzi
    Iannazzi almost 6 years
    This took me hours to figure out.... I accidentally named my unit test project the same name as the main project, so the unit test project dll must have been overwriting the project dll
  • Keith Ketterer
    Keith Ketterer over 5 years
    After checking application pool, "Enable 32-Bit Applications" was set to False, but my platform target was x86. Changing it to Any CPU OR x64 fixed my issue.
  • Appsum Solutions
    Appsum Solutions over 4 years
    When I merged a project from 1 server to another, this flag was indeed False again, thanks for the solution!
  • Zujaj Misbah Khan
    Zujaj Misbah Khan over 4 years
    Excellent! My dll file name and the namespace were different, I copied the namespace and renamed my dll.
  • Mike Lowery
    Mike Lowery about 4 years
  • stevejoy32
    stevejoy32 about 3 years
    Yeah, same here, combined with doing a Clean Solution. After I did that, VS highlighted a build error that wasn't showing up before. Previously it said Rebuild All Succeeded after rebuilding - I was referencing the wrong namespace for a class.
  • Burhan
    Burhan almost 3 years
    Worked for me, I just deleted the bin/ folder and built the solution again.