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=22.214.171.124, 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 126.96.36.199 in any of my projects.
Any ideas how I should go about solving this?
I would also appreciate tips on how to debug problems like this in general.
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.
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.
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.
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
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
You can download missings dll from google and copy in right path (in my case
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
Despite the original question being posted five years ago, the problem still persists and is rather annoying.
The general solution is thorough analysis of all referenced assemblies to understand what's going wrong. To make this task easier I made a tool (a Visual Studio extension) which allows selecting a .NET assembly (a
.exe file) to get a graph of all the referenced assemblies while highlighting conflicting or missing references.
The tool is available in Visual Studio Gallery: https://marketplace.visualstudio.com/vsgallery/051172f3-4b30-4bbc-8da6-d55f70402734
Microsoft Enterprise Library (referenced by .NetTiers) was our problem, which was in turn referencing an older version of Unity. In order to solve the problem we used the following binding redirection in the web.config:
<configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="188.8.131.52-2.0.414.0" newVersion="2.1.505.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Microsoft.Practices.Unity.Configuration" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="184.108.40.206-2.0.414.0" newVersion="2.1.505.0" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
Alternatively, you may want to just update the Enterprise Library to the latest version.
Juntos answer is correct but you should also consider:
For the unity v2.1.505.2 different AssemblyVersion and AssemblyFileVersion attributes are specified:
AssemblyFileVersion is used by the NuGet but CLR does not care about it! CLR is going to use only AssemblyVersion!
So your redirects should be applied to a version that specified in AssemblyVersion attribute. So 2.1.505.0 should be used
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-2.1.505.0" newVersion="2.1.505.0" /> </dependentAssembly> </assemblyBinding>
I also got this terrible error and found a solution for this...
- Right Click on the Solution name
- Click Clean Solution
- Restart Visual Studio
- Goto project Properties >> Build
- Change Configuration to Release
- Start Debugging (F5)
1) , 2)
4) , 5)
Hope this will help you also.
You say you have a lot of projects in your solution ... well, start with one near the top of the build order. Get that one to build and once you figure it out you can apply the same fix to the rest of them.
Honestly, you probably just need to refresh your reference. It sounds like you either updated your version and didn't update the references, or it's a relative path issue if you keep your solution in source control. Just verify your assumptions, and re-add the reference.
Following worked for me.
if you are getting this error message by opening an application on you windows xp it mean first you have installed that app due to its not working without net framework 4 and service pack 3 . you installed both and again you are getting this error so you should reinstall that app again but first uninstall from add and remove
if this not work please dont abuse me . i am also a junior
Look out for conflicting references. Even after a clean and rebuild, conflicting references will still cause a problem. My problem was between AForge and Accord. I removed both of the references, and re-added the references re-choosing the particular reference (particular to my case, just Accord).
I had this today, and in my case the issue was very odd:
<dependentAssembly> <assemblyIdentity name="Microsoft.Owin.Host.SystemWeb" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-3.1.0" newVersion="220.127.116.11" /> </dependentAssembly>0.
Note the stray characters at the end of the XML - somehow those had been moved from the version number to the end of this block of XML!
<dependentAssembly> <assemblyIdentity name="Microsoft.Owin.Host.SystemWeb" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-18.104.22.168" newVersion="22.214.171.124" /> </dependentAssembly>
Changed to the above and voila! Everything worked again.
Okay this may sound very stupid, but heres how I solved the issue after trying out every other solution and spending a night on this stupid thing.
I was getting the same error with some DLL missing from Bin Folder. I tried to delete , get back up everything from Team Foundation Server but didn't work. Got a copy of Bin folder from my office-matelocal machine, and replaced it. It didn't work either. At last, I manually FTPed server, got the copy of DLL which was showing up as missing, and then it started showing up that next file in the file list sequence is missing.
So I ftped server Got all Bin Folder, Manually replaced each file one by one. (Not Ctrl + All and replace.. I tried : it didn't work.) And somehow it worked...
I kept getting this error on my web forms project in visual studio 2015. I shutdown Visual Studio and I killed the ScriptedSandbox64.exe, Microsoft.VsHub.Server.HttpHostx64.exe, Microsoft.VsHub.Server.HttpHostx.exe *32, Microsoft.VisualStudio.Web.Host.exe *32 processes and it seemed to help fix the issue.
Clean the solution and then right click on the project and select
Here increment the
Assembly file version and rebuild.
If that does not work,
1 - Open the solution in file Explorer.
2 - Close Visual Studio.
3 - Remove all
4 - Reopen the project and build it.
I had this problem, the mistake was actually very silly. I had specified the wrong location for the .dll file, after changing the location to correct location the loading happened correctly (answering so someone else don't make this mistake).
For me, it seems that Nuget wasn't playing nice with my project/solution. I used Nuget to install NewtonSoft.Json The project file seemed to reference it correctly, and when I R-clicked the dll name in Solution Explorer/Dependencies/Nuget, then clicked Properties, I found that the dll existed where properties said it should be.
I deleted the Nuget package and did R-click Project > Add > Reference and browsed to the dll in a packages directory when a former Nuget process had installed it, and then the Solution ran fine.
NOTES: this solution is quite a a hodge podge, starting with a Xamarin.iOS solution and adding a .netstandard project (which is where I had difficulty using Nuget). There is also a "portable" project in the solution. I inherited all this from a dev who has been gone for 3 years. Ha ha.
I have a C# Winforms project called SetTags with a large number of forms that I use Visual Studio 2013 to work on. After editing one of them and trying to build I got the error:
Could not load file or assembly 'SetTags Version = 126.96.36.199, Culture=neutral,PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
The error also appeared when I tried to save the project or to close the form I had been working on.
I fixed the problem by removing a recently added radio button control and commenting out all references to it, then added the control again and uncommenting the code. This allowed me to save the form, and on closing restarting VS the problem had disappeared.
My Visual Studio environment has many occasional problems - Toolbox not showing or appearing only on VS startup, unrecognized custom controls when trying to view a form in Design mode - and it may be that I need to move on to a later VS version.
A strange fix for me, but I had just pulled this solution from source control.
Was getting this error, went through most of the answers above, and then deleted the solution and re-pulled the solution from source control.
Will only apply to a few, but I guess I was one of the few so there will be more. Not sure what happened the first time, but somehow some assemblies must have had some issues when I pulled them across.
Essentially turn it off and on again.
I wasted a few frustrating hours on this problem too. We had to update our version of the .NET Framework, and started getting multiple “Could not load file or assembly or one of its dependencies” for several DLLs that had not been changed for years. Strangely, the versions being searched for in the error messages were all extremely old. For example, it was searching for Newtonsoft.Json version 6.0.0 while we had been using 8.0.1 for years.
Reverting to these ancient versions was not an option, and anyway there were a bunch of
bindingRedirect elements in our web.config file that were supposed to redirect calls to old DLLs to the new ones. Rolling back the .NET version made the errors go away, but we needed the new version. What is going on?
<runtime> element in our web.config file contained the element:
<assemblyBinding appliesTo="v2.0.50727" xmlns="urn:schemas-microsoft-com:asm.v1">
dependentAssembly elements that seemed to be ignored were contained in that.
The culprit was the
appliesTo attribute. It meant the
bindingRedirect applies only to .NET version 2.0.50727. When we updated the .NET Framework version, all our bindingRedirect elements were ignored.
The solution in our case was to remove the
appliesTo attribute entirely.
Your project's csproj file must contain a package reference of Microsoft.Practices.Unity and this could not be found in the global-packages folder (%userprofile%.nuget\packages), running
dotnet restore fixes the issue
TLDR; the solution for me was to restore default settings in visual studio.
I'm on visual studio 2019 community edition and I had this issue for same dll file across different projects that I didn't touch.
After trying out all the answers in this question (as of 2020-07-22 7:13UTC) I decided to repair visual studio installation (backed up my settings beforehand). After installation opened the solutions that had the problem and the problem was gone. After that imported my settings that and the problem came back!! So without repairing visual studio installation again (which takes a few minutes + one restart) I've simply restored VS default settings and then it works. If I end up having time to investigate, I'll edit the answer and pinpoint the underlaying issue
I do the following to work out which dependency cannot be found.
Run regedit.exe and navigate to:
Create the following:
LogFailures set value to 1 (DWORD) LogResourceBinds set value to 1 (DWORD) LogPath (String) set value to C:\FusionLog\
Now run your program and wait for it to raise
Could not load file or assembly or one of its dependencies.
Using explorer, navigate to
C:\FusionLog and there should be a folder containing logs for your program, showing which dependency is missing.
Note: Some people use FUSLOGVW.exe, which is a viewer for these Fusion Logs. On my machine it can be found in multiple places, including:
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.2 Tools\x64\FUSLOGVW.exe
User contributions licensed under CC BY-SA 3.0