Could not load file or assembly or one of its dependencies
Asked Answered
H

45

334

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?

Hickie answered 17/12, 2010 at 11:13 Comment(7)
Could any of your referenced assemblies be using some stuff in old Unity library?Siberson
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...Hickie
You only have to look into the referenced assemblies in the project for which you get this error.Siberson
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.Todhunter
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.Farris
Possible duplicate of Could not load file or assembly 'Microsoft.Practices.Unity'Mochun
"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 thinggyKeratin
G
138
  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.

Gelderland answered 17/12, 2010 at 11:30 Comment(3)
Where's the log file of FuseLogVwPreventer
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.Greybeard
Other tips: 1) Run the tool as admin 2) Go to the tool's settings and make sure that you have chosen "Log bind failures to disk" 3) You ~may~ need to restart IIS Admin Service to see the desired outputBolme
V
96

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.

Varnish answered 7/10, 2013 at 10:58 Comment(4)
IIS -> select each ApplicationPool -> Basic Settings -> check if the latest framework is selected under the ".NET Framework version" dropdownRecognizee
You can also right click your project in VS . and remove the prefer 32 bit checkmarkEva
Thanks. It worked. Well it was already True in my case , just for try. I made it False and it worked.Ellery
When I merged a project from 1 server to another, this flag was indeed False again, thanks for the solution!Magnolia
C
88

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.

Churchy answered 15/2, 2012 at 5:27 Comment(1)
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.Bona
B
59

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

Brassy answered 17/12, 2010 at 11:28 Comment(4)
This issue can be caused by a lot of things ... your solution solved my problems, and might solve others' as well.Cline
@ScottRippey This worked for me to. I first deleted all .pdb files and then reloaded my project and rebuild it.Sharkskin
Worked for me, I just deleted the bin/ folder and built the solution again.Sepaloid
And still in 2023 this fairly annoying issue is present in VS2022. Thank you for this solution!Marabelle
C
39

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 .dll or .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

Example of output: enter image description here

Cero answered 29/5, 2017 at 22:34 Comment(4)
Does not work with Community editions of Visual StudioKerrykersey
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.Cero
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#VersionSupportKerrykersey
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 -> ModifyCero
L
33

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

Lipetsk answered 27/5, 2016 at 12:47 Comment(3)
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.Joubert
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.Inchmeal
This may solve my problem, but MalwareBytes is warning me from using the site.Lord
C
17

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="1.0.0.0-2.0.414.0" newVersion="2.1.505.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="Microsoft.Practices.Unity.Configuration" publicKeyToken="31bf3856ad364e35" culture="neutral" />
                <bindingRedirect oldVersion="1.0.0.0-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.

Charlenecharleroi answered 3/7, 2012 at 10:3 Comment(0)
K
17

Following worked for me.

  • Remove Temporary Files C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
  • Close VSTS and Open Again
  • Remove and Add the same DLLs (Note: you add the same matching versions)
Killian answered 22/3, 2013 at 7:22 Comment(0)
I
16

screenshotIn solution explorer right click on project (not solution), in build tab choose Platform target : "Any CPU".

Isochroous answered 26/9, 2016 at 14:12 Comment(1)
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.Endres
P
15

Check the Web.config/App.config file in your project. See if the version numbers are correct.

<bindingRedirect oldVersion="X.X.X.X-X.X.X.X" newVersion="X.X.X.X" />

This worked for me.

Palstave answered 7/4, 2015 at 17:29 Comment(1)
This worked for me although it was web.config, not app.configConstantine
T
13

Sometimes packages have different versions specificed for AssemblyVersion and AssemblyFileVersion.

I had this situation for the unity:

  • AssemblyFileVersion is a version used by NuGet package manager - v2.1.505.2
  • AssemblyVersion is a version used by CLR - v2.1.505.0

enter image description here

You have to specify redirects using an AssemblyVersion attribute. In my example pictures 2.1.505.0 should be used instead of 2.1.505.2

<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>

You can also check next materials: What are differences between AssemblyVersion, AssemblyFileVersion and AssemblyInformationalVersion?

Theodoratheodore answered 26/11, 2014 at 11:15 Comment(0)
S
8

I also got this terrible error and found a solution for this...

  1. Right Click on the Solution name
  2. Click Clean Solution
  3. Restart Visual Studio
  4. Goto project Properties >> Build
  5. Change Configuration to Release
  6. Start Debugging (F5)

1) , 2)

Right Click on the Solution name

4) , 5)

Change Configuration to Release

Hope this will help you also.

Scraggy answered 17/9, 2015 at 18:24 Comment(0)
D
6

I had the same problem i solved it via the instructions below:

  1. open tools menu and select option
  2. in options, window go to Projects and Solutions/Web Projects
  3. check use the 64bit version of IIS ...

enter image description here

Dania answered 12/6, 2019 at 8:31 Comment(0)
T
5

Not sure if this might help.

Check that the Assembly name and the Default namespace in the Properies in your asemblies match. This resolved my issue which yielded the same error.

Tarah answered 17/4, 2012 at 10:27 Comment(1)
Excellent! My dll file name and the namespace were different, I copied the namespace and renamed my dll.Wilk
P
5
  • Goto :Solution -> Package
  • Click on Advanced Tab (Find below the page)
  • Add your dll to additional assemblies(this way we can add external dlls in sharepoint).
Profanity answered 12/9, 2013 at 6:26 Comment(1)
I dont have "Solution -> Package" in my VS2010 projectGonadotropin
A
5

In my case in the bin folder was a non reference dll called Unity.MVC3 , i tried to search any reference to this in visual studio without success, so my solution was so easy as delete that dll from the bin folder.

Arneson answered 5/1, 2016 at 0:0 Comment(0)
I
4

Thanks Riddhi M. Following worked for me.

Remove Temporary Files C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files Close VSTS and Open Again Remove and Add the same DLLs (Note: you add the same matching versions)

Incuse answered 30/7, 2015 at 13:29 Comment(1)
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.Weatherbeaten
T
4

Tried closing and re-opening VS as suggested but it didn't work out.

I had to change from MIXED PLATFORMS to ANY CPU.

enter image description here

Thundershower answered 30/8, 2021 at 14:58 Comment(0)
K
3

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.

Kremlin answered 17/12, 2010 at 11:30 Comment(0)
I
3

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

Italianism answered 16/11, 2013 at 8:14 Comment(0)
A
3

Following worked for me.

  • Remove Temporary Files C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
    • then right click on Temporary Asp.net Files>properties>security and give total control access to IIS and to all user runing my project
Asp answered 6/3, 2015 at 15:38 Comment(0)
S
3

This issue happened to me where one of my dependent libraries was compiling a DLL with "Any CPU" when the parent library was expecting a compilation of "x64".

Shopping answered 16/11, 2016 at 17:21 Comment(1)
#517230Tetraploid
D
3

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="3.1.0.0" />
  </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-3.1.0.0" newVersion="3.1.0.0" />
  </dependentAssembly>

Changed to the above and voila! Everything worked again.

Drive answered 12/5, 2017 at 9:16 Comment(0)
B
2

You have to delete Your appname.dll file from your output folder. Cleanup Debug and Release folders. Rebuild and copy to output folder regenerated dll file.

Benoite answered 15/5, 2013 at 7:44 Comment(0)
J
2

I "Set as Startup Project" the unloaded/unfound library/project.

Then deployed it.

It worked!

I think it couldn't found the .dll because it was not in the assembly at first.

Jaenicke answered 16/7, 2013 at 5:8 Comment(0)
I
2

Another possible cause: make sure you haven't accidentally given both of the projects the same assembly name in project properties.

Indiscerptible answered 21/12, 2014 at 16:33 Comment(1)
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 dllKhalsa
I
2

My solution for .NET 4.0, using Enterprise Library 5, was to add a reference to:

Microsoft.Practices.Unity.Interception.dll

Interior answered 5/6, 2015 at 19:44 Comment(0)
W
2

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).

Warnock answered 25/3, 2016 at 19:5 Comment(0)
G
2

For me rebuilding the unity game without Unity C# Projects Checkmark worked.

Geber answered 9/5, 2016 at 12:38 Comment(0)
A
2

In my case, none of the proposed answer worked.

Here is what worked for me:

  1. Remove the reference
  2. Rename the DLL
  3. Import the reference again

The second step was important apparently as it did not work without it.

Adultery answered 23/6, 2016 at 8:38 Comment(0)
S
2

Try checking if the "Copy to Local" property for the reference is set to true and the specific version is set to true. This is relevant for applications in Visual Studio.

Shotgun answered 6/7, 2016 at 15:33 Comment(0)
O
2

Clean the solution and then right click on the project and select Package

Here increment the Assembly and Assembly file version and rebuild.

enter image description here

If that does not work,

1 - Open the solution in file Explorer.

2 - Close Visual Studio.

3 - Remove all bin and obj folders.

4 - Reopen the project and build it.

Overstrung answered 30/1, 2020 at 20:22 Comment(1)
I only needed to delete the obj folder and compile againSupper
A
1

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...

Arbitrate answered 19/2, 2014 at 15:33 Comment(0)
C
1

My solution was:

I have a three-tier application and I forgot to copy the DLL also to the right path at IIS. Just after copied it to the right place it worked for me.

Circumjacent answered 23/9, 2016 at 13:17 Comment(0)
D
1

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.

Dissimilate answered 20/4, 2017 at 22:20 Comment(0)
L
1

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?

The <runtime> element in our web.config file contained the element:

<assemblyBinding appliesTo="v2.0.50727"
    xmlns="urn:schemas-microsoft-com:asm.v1">

The 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.

Lamdin answered 6/2, 2020 at 1:36 Comment(0)
J
1

I do the following to work out which dependency cannot be found.

Run regedit.exe and navigate to:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion

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
Jalopy answered 12/9, 2020 at 9:59 Comment(0)
H
0

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).

Handicapper answered 26/3, 2014 at 16:7 Comment(0)
E
0

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.

Epithelioma answered 15/3, 2019 at 18:9 Comment(0)
M
0

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 = 2.1.85.0, 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.

Mashie answered 14/10, 2019 at 22:25 Comment(0)
M
0

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.

Worked.

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.

Mcburney answered 11/12, 2019 at 9:28 Comment(0)
M
0

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

Mak answered 1/6, 2020 at 18:48 Comment(0)
P
0

Step 1: Remove the Existing Reference Step 2: Clean Solution Step 3: Add project Reference again.

and its done. :)

Pipestone answered 12/6, 2020 at 19:13 Comment(0)
A
0

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

Armhole answered 22/7, 2020 at 7:18 Comment(0)
D
0

I know this is an old post, but I made a PowerShell module to list dependencies, and which ones failed to load.
You can install it with:

Install-Module LibSnitcher
Import-Module LibSnitcher

To list the complete dependency chain:
(You can use the -Depth parameter to set the recursion depth)

Get-PeDependencyChain -Path C:\Path\To\Your\Module.dll

To list modules that failed to load:

Get-PeFailedDependency -Path C:\Path\To\Your\Module.dll

There is a complete README at the project page, here

Hope it helps, let me know how can I improve it!

Devondevona answered 21/8, 2023 at 22:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.