Could not load file or assembly or one of its dependencies
Solution 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 theServiceLocator
you should provide it with the old version of Unity, and that makes the problem.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:
-
Download Dependency Walker from http://www.dependencywalker.com/
-
Launch Dependency Walker and open the dll (in my case
NativeInterfaces.dll
) -
You can see one or more dll with the error in red Error opening file...
-
It means that this dll is missing in your system; in my case the dll name is
MSVCR71.DLL
-
You can download missings dll from google and copy in right path (in my case
c:\windows\system32
) -
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
-
Restart your application
Related videos on Youtube
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, 2022Comments
-
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 over 13 yearsCould any of your referenced assemblies be using some stuff in old
Unity
library? -
ronag over 13 yearsProbably... 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 over 13 yearsYou only have to look into the referenced assemblies in the project for which you get this error.
-
user1703401 over 13 yearsIt'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 almost 9 yearsLook 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 about 8 yearsPossible duplicate of Could not load file or assembly 'Microsoft.Practices.Unity'
-
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 over 12 yearsThis issue can be caused by a lot of things ... your solution solved my problems, and might solve others' as well.
-
Martin over 10 yearsIIS -> select each ApplicationPool -> Basic Settings -> check if the latest framework is selected under the ".NET Framework version" dropdown
-
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 almost 10 yearsWhere's the log file of FuseLogVw
-
eran otzap over 9 yearsYou can also right click your project in VS . and remove the prefer 32 bit checkmark
-
RedGreenCode over 9 yearsTo 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 almost 9 yearsI dont have "Solution -> Package" in my VS2010 project
-
Dhir Pratap over 7 yearsDependency 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 over 7 yearsThanks. It worked. Well it was already True in my case , just for try. I made it False and it worked.
-
Draex_ almost 7 yearsDoes not work with Community editions of Visual Studio
-
Mykola Tarasyuk almost 7 yearsI 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_ almost 7 yearsAha. 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#VersionSupport
-
Mykola Tarasyuk over 6 yearsThere 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 over 6 yearsThis worked for me although it was web.config, not app.config
-
Bonez024 over 6 yearsSpent 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 about 6 yearsI 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 almost 6 yearsThis 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 over 5 yearsAfter 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 over 4 yearsWhen I merged a project from 1 server to another, this flag was indeed False again, thanks for the solution!
-
Zujaj Misbah Khan over 4 yearsExcellent! My dll file name and the namespace were different, I copied the namespace and renamed my dll.
-
Mike Lowery about 4 years
-
stevejoy32 about 3 yearsYeah, 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 almost 3 yearsWorked for me, I just deleted the
bin/
folder and built the solution again.