The located assembly's manifest definition does not match the assembly reference
Asked Answered
D

62

914

I am trying to run some unit tests in a C# Windows Forms application (Visual Studio 2005), and I get the following error:

System.IO.FileLoadException: Could not load file or assembly 'Utility, Version=1.2.0.200, Culture=neutral, PublicKeyToken=764d581291d764f7' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)**

at x.Foo.FooGO()

at x.Foo.Foo2(String groupName_) in Foo.cs:line 123

at x.Foo.UnitTests.FooTests.TestFoo() in FooTests.cs:line 98**

System.IO.FileLoadException: Could not load file or assembly 'Utility, Version=1.2.0.203, Culture=neutral, PublicKeyToken=764d581291d764f7' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

I look in my references, and I only have a reference to Utility version 1.2.0.203 (the other one is old).

Any suggestions on how I figure out what is trying to reference this old version of this DLL file?

Besides, I don't think I even have this old assembly on my hard drive. Is there any tool to search for this old versioned assembly?

Donkey answered 18/10, 2008 at 13:16 Comment(2)
In my case, this happened because I had two projects loading the same DLL with different versions. (hope this helps someone!)Syndesmosis
This question is really old, and answers mentioning the GAC (and not mentioning Nuget) are probably outdated.Lowder
W
506

The .NET Assembly loader:

  • is unable to find 1.2.0.203
  • but did find a 1.2.0.200

This assembly does not match what was requested and therefore you get this error.

In simple words, it can't find the assembly that was referenced. Make sure it can find the right assembly by putting it in the GAC or in the application path.

run below command to add the assembly dll file to GAC:

gacutil /i "path/to/my.dll"

Also see https://learn.microsoft.com/archive/blogs/junfeng/the-located-assemblys-manifest-definition-with-name-xxx-dll-does-not-match-the-assembly-reference.

Waac answered 18/10, 2008 at 13:39 Comment(16)
but when i look at references of the project, it is pointing to 1.2.0.203 .. . nothing seems to be pointing to 1.2.0.200 anymoreDonkey
Exactly - it's looking for 1.2.0.203, but it found 1.2.0.200. Find out where that file is and replace it with the right version.Otiose
I asked a similar question here and got a working solution: #4188407Barometer
Check the references version, and then look if its the same in packages.config and Web.configSachasachem
details on running fuslogw as referenced in the above link to JunFeng blog blogs.msdn.com/b/suzcook/archive/2003/05/29/57120.aspxAlfredalfreda
In my case under Build > Publish, I had "Delete all existing files prior to publish" unchecked, so it was using an old version of the DLL on the server and wasn't overwriting it with the newer version I had locally. Once I checked that it pushed the right version to IIS and fixed it.Owings
I had this error with a nuget package that was totally missing. When I went to nuget and installed the package the error was fixed.Geothermal
@Lars Truijens how did you know it found 1.0.200? I can't see 200 mentioned in the OP's stacktrace?Redan
@OnlineUser02094: It says so literally in the Exception Message: Version=1.2.0.200Waac
This message confuses me every time. It seems to be written backwards. I'd expect it to complain about the version you've asked to load, not the version it found. Glad I'm not the only one who gets it wrong!Hamm
I searched for the offending assembly in nuget, installed it (with a new version) and the problem disappeared.Ileneileo
I was having an identical error on an Azure function project and with the help of fuslogvw.exe @ra170 identify that assemblyIdentity Microsoft.Azure.Storage.Common" was missing from func.exe.Config. So I added this : <dependentAssembly> <assemblyIdentity name="Microsoft.Azure.Storage.Common" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" /> </dependentAssembly>Tranquillize
In my case somehow Web.config file was simply missing and I get the above error.Rampart
I thought the Web.config was there, but the account I used on the production server had the setting to hide known file extensions. So in the Windows Explorer I saw a Web.config, which was in fact Web.config.txt.Haematin
Problem appears only when installing over an existing installation using VS2019 installer (with uninstall earlier version checked). Seems to be looking for the earlier install version of the dll.Ileneileo
The problem was caused by a reference to DLL with v 106.8.10.0 in the earlier version of the project and the DLL v 105.2.3.0 referenced from DLL2 which appeared in the later version. Because the referenced version from DLL2 (detected with Dependencies) was earlier than the DLL already present from the earlier version, it wasn't replaced by the new version so DLL2 referencing v 105.2.3.0 failed as it wasn't there. Fix was to download the open source for the DLL2 referencing DLL 105.2.3.0 and rebuild it with the latest version 106.11.7.0. This needed an update to nuget.exe!Ileneileo
G
102

You can do a couple of things to troubleshoot this issue. First, use Windows file search to search your hard drive for your assembly (.dll). Once you have a list of results, do View->Choose Details... and then check "File Version". This will display the version number in the list of results, so you can see where the old version might be coming from.

Also, like Lars said, check your GAC to see what version is listed there. This Microsoft article states that assemblies found in the GAC are not copied locally during a build, so you might need to remove the old version before doing a rebuild all. (See my answer to this question for notes on creating a batch file to do this for you)

If you still can't figure out where the old version is coming from, you can use the fuslogvw.exe application that ships with Visual Studio to get more information about the binding failures. Microsoft has information about this tool here. Note that you'll have to enable logging by setting the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion\EnableLog registry key to 1.

Gwenngwenneth answered 20/10, 2008 at 21:31 Comment(7)
Don't forget that the File Version is not part of the assemblies identity. The Assembly Version is, but does not have to be the same as the File Version!Waac
If using fuslogvw for services read blogs.msdn.com/b/junfeng/archive/2004/02/14/72912.aspxDibri
Searching for the filename solved my problem. I had an old version of the dll in my Temporary ASP.Net folder and InstallShield was using that instead of the up to date version! Clean solution, rebuild, restart PC did nothing. Worked fine locally and blew up every time it was deployed.Kester
Immediately after building, my site works fine, but a little while later, this problem crops up.Bronk
I edited this answer to say assembly version instead.Pardue
<add assembly version="X.X.X.X" ... in the web.config file set to the DLL's file version solved the error in the subject in my case completely.Pythagorean
All these years later and you're still helping me Seth.Modernistic
J
68

I just ran into this problem myself, and I found that the issue was something different than what the others have run into.

I had two DLLs that my main project was referencing: CompanyClasses.dll and CompanyControls.dll. I was getting a run-time error saying:

Could not load file or assembly 'CompanyClasses, Version=1.4.1.0, Culture=neutral, PublicKeyToken=045746ba8544160c' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference

Trouble was, I didn't have any CompanyClasses.dll files on my system with a version number of 1.4.1. None in the GAC, none in the app folders...none anywhere. I searched my entire hard drive. All the CompanyClasses.dll files I had were 1.4.2.

The real problem, I found, was that CompanyControls.dll referenced version 1.4.1 of CompanyClasses.dll. I just recompiled CompanyControls.dll (after having it reference CompanyClasses.dll 1.4.2) and this error went away for me.

Jewelfish answered 17/11, 2009 at 19:15 Comment(5)
+1 Something similar happened to me when I have one of my DLLs reference an older version of Caliburn Micro.Lysias
me too, your experience sparked me where I need to look and I got my issue fixed.Jujitsu
Another option would be to open the CompanyControls project, right-click the CompanyClasses.dll reference --> properties --> SpecificVersion = falseProtuberant
this is very often case on xamarin applications. I had xamarin.forms project different than xamarin.droid project. I just saw your post and I recognized it.Helsa
If CompanyClasses.dll is signed, then SpecificVersion = false alone won't cut it. You'll need a bindingredirect.Americanism
D
68

I am going to blow everyone's mind right now . . .

Delete all the <assemblyBinding> references from your .config file, and then run this command from the NuGet Package Manager console:

Get-Project -All | Add-BindingRedirect
Decurion answered 24/1, 2019 at 19:27 Comment(7)
you saved my time 👌👌Gonidium
this works only when package management format is packages.config, if you are using 2017 csproj without packages.config, it doenst work :(Reinhardt
Mind officially blownPict
I believe that new-style csproj projects will automatically generate binding redirects in app.config files on build (the redirects don't need to be added to project app.config files, but will exist in the output).Nittygritty
I had updated this product over time... sometimes just flushing the artifacts and having a do over is needed. I think the only thing different I could have done was create a new project and hand pick the elements into it... this command saved me from having to do that... Someday I will have to pay the technical debt? Maybe, but not today evil.Dollarbird
This touches all projects in your solution. So for touching only single projects first call Get-Project MyProject to verify it finds exactly what you want. Then call Get-Project MyProject | Add-BindingRedirect.Lallygag
Thank you so much, this saved me a TON of time, I had been trying to manually repair these and this solved my issueIsom
T
62

The following redirects any assembly version to version 3.1.0.0. We have a script that will always update this reference in the App.config so we never have to deal with this issue again.

Through reflection you can get the assembly publicKeyToken and generate this block from the .dll file itself.

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
 <dependentAssembly>
    <assemblyIdentity name="Castle.Core" publicKeyToken="407dd0808d44fbdc" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="3.1.0.0" />
  </dependentAssembly>
</assemblyBinding>

Note that without an XML namespace attribute (xmlns) this will not work.

Teth answered 2/11, 2012 at 0:34 Comment(4)
This worked for me. I changed the 'newVersion=3.3.3' to 'newVersion=3.1.0'Bant
Best not to go down the rebinding route if you can avoid it though. When that bug comes to bite you it'll bite hard.Giltedged
My issue was the fact that the redirects were pointing to non-existent assemblies.The App.Config held assembly info from the latest NuGet packages I'd installed. When I downgraded these packages later, it did NOT clean this up. This was a .NET standard class library being hit by a 4.7.2 framework unit test project. The unit test project's issue presented at runtime..Roosevelt
@Roosevelt is right. If your source control indicates that web.config has changes (because you've been playing with your NuGets) you might be wise to back those bindingRedirects out of there. Downgrading NuGets will not clean up the binding redirectsTauromachy
K
52

If you are using Visual Studio, try "clean solution" and then rebuild your project.

Kessiah answered 13/7, 2010 at 3:27 Comment(9)
This is usually the solution for me. Often, deleting bin and obj do it. Basically, something I used to reference is still sitting there trying to satisfy the same requirement. For example, an old version being something I referenced directly and the new version being on NuGet.Dottie
Encountered this problem for several DLLs after pulling from TFS. This solution fixed it for me.Mien
Worked for me. Deleted out the bin amd obj folder and resolved the issue.Group
Thanks, worked for me also, just deleting the bin folder.Letsou
For me it was enough to delete bin folder. Surprisingly, I tried clean solution and rebuild solution before without success. Sometimes a bit strange.Galilean
"Clean solution" didn't do anything for me. (Microsoft????) But deleting the bin and obj folders fixed it. Thanks!Blind
deleted bin and obj folders and it worked. clean solution didn't workGallicism
Love those easy fixes! Worked for me.Tartan
@Blind Microsoft should add a "Deep clean" option in Visual Studio xDTombola
T
43

The other answers wouldn't work for me. If you don't care about the version and you just want your app to run then right click on the reference and set 'specific version' to false...This worked for me. enter image description here

Tameratamerlane answered 28/6, 2013 at 17:21 Comment(1)
That setting has only effect at compile time. After it is compiled, it will need the exact same assembly version with which you compiled it. See #24022634Waac
R
35

In my case, this error occurred while running an ASP.NET application. The solution was to:

  1. Delete the obj and bin folders in the project folder

Clean didn't work, rebuild didn't work, all references were fine, but it wasn't writing one of the libraries. After deleting those directories, everything worked perfectly.

Reside answered 9/10, 2016 at 18:34 Comment(4)
Thanks, Levi Fuller.This answer should be higher up; for my situation it was spot on! For me this error started when I made a backup copy of my web.config and Visual Studio kept loading this config file instead of the actual config, even after I deleted the duplicate copy. This solved it. Thanks.Slater
Works for me too. Still unsure why this works though :(Pandemic
Thank you so much. This finally got it working after hours of troubleshooting. In my case, the problem happened after I accidentally upgraded some NuGet packages, then reverted the changes in my working copy (packages.config, .csproj).Genro
For Azure app service on linux I deleted all files in wwwroot and redeployed, then the app service started normally with no errors.Lumbye
R
30

I added a NuGet package, only to realize a black-box portion of my application was referencing an older version of the library.

I removed the package and referenced the older version's static DLL file, but the web.config file was never updated from:

<dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
    <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="6.0.0.0" />
</dependentAssembly>

to what it should have reverted to when I uninstalled the package:

<dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.5.0.0" />
</dependentAssembly>
Ronnie answered 5/3, 2014 at 16:22 Comment(1)
I've seen this where, at least for the Entity Framework module when you use NuGet, if you right-click your solution, go to Manage NuGet Packages for Solution, then Installed Packages > All, select that module, select Manage, you can usually deselect it from your project. That should clean out things like this without having to do it manually --- assuming the vendor did their due diligence. But good catch as apparently sometimes they don't, if that's how you removed it.Radial
R
22

I just ran across this issue and the problem was I had an old copy of the .dll in my application debug directory. You might want to also check there (instead of the GAC) to see if you see it.

Rugged answered 3/9, 2009 at 0:0 Comment(1)
We just migrates to a different server had this issue cause we keep backups. Worked after deleting backup copies. Thanks :)Forsworn
L
16

Is possible you have a wrong nugget versions in assemblyBinding try:

  1. Remove all assembly binding content in web.config / app.config:
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Extensions.Logging.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.1.3.0" newVersion="3.1.3.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Extensions.DependencyInjection" publicKeyToken="adb9793829ddae60" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.1.3.0" newVersion="3.1.3.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
  </dependentAssembly>
</assemblyBinding>
  1. Type in Package Manager Console: Add-BindingRedirect
  2. All necessary binding redirects are generated
  3. Run your application and see if it works properly. If not, add any missing binding redirects that the package console missed.
Lottie answered 27/2, 2021 at 12:45 Comment(3)
Thanks a lot!!! Saved my day (lost 2 hours though)!Pyramid
I'd like to highlight the significance of this answer. Deleting these was exactly the solution to the problem I had. In addition to that, be reminded that you can add paths in 'Project Settings/Reference Paths' in case there is some DLL not loaded. This may be relevant if a DLL you reference uses references on its own, for example if you are in a company that uses some common paths for DLLs.Unwished
I recommend deleting these and NOT doing the Add-BindingRedirect first. If it still doesn't work, then do that as a second step.Dundalk
O
14

In my case it was an old version of the DLL in C:\WINDOWS\Microsoft.NET\Framework\~\Temporary ASP.NET Files\ directory. You can either delete or replace the old version, or you can remove and add back the reference to the DLL in your project. Basically, either way will create a new pointer to the temporary ASP.NET Files.

Orelle answered 15/9, 2010 at 17:7 Comment(2)
This worked for me when I closed Visual Studio, stopped IIS, and deleted all temporary ASP.NET files. Note there can be files in the Framework and Framework64 folder if on 64 bit machine, as well as in the .NET 2.0 and 4.0 folders!Scientist
I used the Windows Start Menu search function to find all DLLs created by my solution and then deleted the whole lot, wherever they were found. I could do this without fear because they should only be created during my Visual Studio debugging. As VS will rebuild such missing DLLs and nothing outside of my solution should be referencing them, this was a "safe" operation for me.Complacence
A
9

I would like to just add that I was creating a basic ASP.NET MVC 4 project and added DotNetOpenAuth.AspNet via NuGet. This resulted in the same error after I referenced a mismatching DLL file for Microsoft.Web.WebPages.OAuth.

To fix it I did a Update-Package and cleaned the solution for a full rebuild.

That worked for me and is kind of a lazy way, but time is money:-P

Attitudinarian answered 28/6, 2013 at 23:17 Comment(3)
Similar answer for me. Update-Package -reinstall re-installs all NuGet packages at the same version.Tombola
This is great; thanks for posting. I tried all of these other great suggestions, but this was the solution that did the trick. Thank goodness for people who are still willing to post an alternate solution, even when there are 80 of them availableDundalk
This solved it for me. My company's library that I recently installed was using an older reference version of the library causing the mismatch. After installation, this threw the error. Update-Package <PackageName> -reinstall brought it back in orderMinestrone
D
8

For us, the problem was caused by something else. The license file for the DevExpress components included two lines, one for an old version of the components that was not installed on this particular computer. Removing the older version from the license file solved the issue.

The annoying part is that the error message gave no indication to what reference was causing the problems.

Dichlorodiphenyltrichloroethane answered 23/11, 2009 at 11:9 Comment(1)
In my case, after upgrading to new DevExpress version, the .resx file of a form contained references to old uninstalled library version. I had to open .resx in code view and either correct the version to new one or delete the invalid entries.Coxswain
W
7

This exact same error is thrown if you try to late bind using reflection, if the assembly you are binding to gets strong-named or has its public-key token changed. The error is the same even though there is not actually any assembly found with the specified public key token.

You need to add the correct public key token (you can get it using sn -T on the dll) to resolve the error. Hope this helps.

Whoa answered 16/7, 2010 at 21:22 Comment(3)
Please elaborate - what is "sn -T"? And where do I add the public key token?Know
"sn.exe" is a tool that comes with Visual Studio, it's a command line tool that can be run from the Visual Studio command prompt. Just run the Visual Studio command prompt (from the start menu), navigate to the folder that contains your assembly, and type "sn -T <assembly>" where <assembly> is the full name of the dll. This gets the Assembly "Token" information. Once you have this, when you are doing late binding with reflection, enter the token info into the assembly id string (i.e., "Assembly=MyAssembly.dll, Public Key Token=<token guid>)Whoa
Thanks for this answer. I was getting this error when referencing a Configuration Section in my App.ini. I had recently signed the assembly, so the PublicKeyToken=null had to be updated with the new (correct) token.Birdella
O
7

I got this error while building on Team Foundation Server's build-service. It turned out I had multiple projects in my solution using different versions of the same library added with NuGet. I removed all old versions with NuGet and added the new one as reference for all.

Team Foundation Server puts all DLL files in one directory, and there can only be one DLL file of a certain name at a time of course.

Okubo answered 16/7, 2015 at 8:28 Comment(1)
Another way is to click "Manage NuGet packages for solution..." and update both your test project and the project under tests to the same (newest) version.Satire
C
5

Mine was a very similar situation to the post by Nathan Bedford but with a slight twist. My project too referenced the changed dll in two ways. 1) Directly and 2) Indirectly by referencing a component (class library) that itself had a reference to the changed dll. Now my Visual studio project for the component(2) referenced the correct version of the changed dll. However the version number of the compnent itself was NOT changed. And as a result the install of the new version of the project failed to replace that component on the client machine.

End result: Direct reference (1) and Indirect reference(2) were pointing to different versions of the changed dll at the client machine. On my dev machine it worked fine.

Resolution: Remove application; Delete all the DLLS from application folder; Re-install.Simple as that in my case.

Cerebrate answered 8/8, 2010 at 17:28 Comment(0)
M
5

My issue was copying source code to a new machine without pulling over any of the referenced assemblies.

Nothing that I did fixed the error, so in haste, I deleted the BIN directory altogether. Rebuilt my source code, and it worked from then on out.

Mm answered 27/4, 2012 at 23:20 Comment(0)
A
5

After trying many of the above solutions with no fix, it came down to making sure 'Auto-generate binding redirects' was turned on within your application in Visual Studio.

enter image description here

More information on enabling automatic binding redirection can be found here: https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/how-to-enable-and-disable-automatic-binding-redirection

Airway answered 24/6, 2020 at 19:12 Comment(0)
R
4

I'll let someone benefit from my shear stupidity. I have some dependencies to a completely separate application (let's call this App1). The dll's from that App1 are pulled into my new application (App2). Any time I do updates in APP1, I have to create new dll's and copy them into App2. Well. . .I got tired of copying and pasting between 2 different App1 versions, so I simply added a 'NEW_' prefix to the dll's.

Well. . . I'm guessing that the build process scans the /bin folder and when it matches something up incorrectly, it barfs with the same error message as noted above. I deleted my "new_" versions and it built just dandy.

Recollect answered 13/3, 2012 at 15:32 Comment(0)
C
4

My app.config contains a

<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.11.0"/>

for npgsql. Somehow on the user's machine, my app.exe.config went missing. I am not sure if it was a silly user, installer glitch, or wacked out anti-virus yet. Replacing the file solved the issue.

Cadman answered 1/10, 2012 at 21:34 Comment(0)
L
3

I just found another reason why to get this error. I cleaned my GAC from all versions of a specific library and built my project with reference to specific version deployed together with the executable. When I run the project I got this exception searching for a newer version of the library.

The reason was publisher policy. When I uninstalled library's versions from GAC I forgot to uninstall publisher policy assemblies as well so instead of using my locally deployed assembly the assembly loader found publisher policy in GAC which told it to search for a newer version.

Liberia answered 1/6, 2012 at 13:7 Comment(0)
Z
3

To me the code coverage configuration in the "Local.testtesttings" file "caused" the problem. I forgot to update the files that were referenced there.

Zymogenic answered 4/3, 2013 at 9:4 Comment(0)
A
3

I faced the same problem while running my unit testcases.

The error clearly states the problem is: when we try to load assembly, the .NET assembly loader tries to load its referred assemblies based on its manifest data (referred assembly name, public key token, version).

To check manifest data:

  1. Open the Visual Studio command prompt,
  2. Type 'ildasm' and drag the required assembly to the ILDASM window and open MANIFEST view. Sometimes MANIFEST contains one assembly with two versions old version as well as new version(like Utility, Version=1.2.0.200 and Utility, Version=1.2.0.203). In reality, the referred assembly is Utility, Version=1.2.0.203(new version), but since the manifest contains even Utility, Version=1.2.0.200(old version), .NET assembly loader tries to find out this versioned DLL file, fails to find and so throws exception.

To solve this, just drag each of the project dependent assemblies to the ILDASM window separately and check which dependent assembly holds the manifest data with the old assembly version. Just rebuild this dependent assembly and refer it back to your project.

Alegar answered 11/3, 2013 at 10:38 Comment(2)
Unfortunately, I can't drag the assembly to ildasm since the error prevents the assembly from being built...Muldrow
This sounds promising but I don't understand how to fix it. I have located a project in my solution that has two versions System.Web.Mvc. When I rebuild it, it still contains two versions. How can I get rid of the reference to the old version?Doggerel
D
3

Just deleting contents of your project's bin folder and rebuild the solution solved my problem.

Dextrorotation answered 10/8, 2017 at 4:15 Comment(1)
Well what do you know, you just helped me out my misery, thanks indeedCopepod
H
3

A general answer to this kind of issue is to use binding redirects as in other answers. However, that's only part of the problem - you need to know the correct version of the assembly file that you're using. Windows properties is not always accurate and nuget is also not always accurate.

The only way to get correct version info is to analyse the file itself. One useful tool is dotPeek. The assembly name listed in dotPeek is always accurate in my experience.

So for example, the correct binding for this file is the following:

<dependentAssembly>
    <assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
    <bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0"/>
</dependentAssembly>

Windows explorer says the file is 4.6.26515.06, nuget says its a 5.0.0.0 file. dotPeek says it is 4.2.1.0 and that is the version that works correctly in our software. Also note that the public key and culture are important and dotPeek also show this information.

dotPeek vs Windows version information

Haymo answered 3/12, 2020 at 12:25 Comment(1)
!!!!!!!!!!This worked instantly : Note that the binding for me that worked was related to the oldVersion -> newVersion. My assembly manifest pointed to the old version, but was never redirected to the new version of the assembly after upgrading to a later of the same DLL.Fungi
K
2

Here's my method of fixing this issue.

  1. From the exception message, get the name of the "problem" library and the "expected" version number.

enter image description here

  1. Find all copies of that .dll in your solution, right-click on them, and check which version of the .dll it is.

enter image description here

Okay, so in this example, my .dll is definitely 2.0.5022.0 (so the Exception version number is wrong).

  1. Search for the version number which was shown in the Exception message in all of the .csproj files in your solution. Replace this version number with the actual number from the dll.

So, in this example, I would replace this...

<Reference Include="DocumentFormat.OpenXml, Version=2.5.5631.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />

... with this...

<Reference Include="DocumentFormat.OpenXml, Version=2.0.5022.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />

Job done !

Konstantin answered 15/11, 2016 at 16:0 Comment(1)
what if my csproj files have no version referenced?Andromede
C
2

The question has already an answer, but if the problem has occurred by NuGet package in different versions in the same solution, you can try the following.

Open NuGet Package Manager, as you see my service project version is different than others.

Then update projects that contain an old version of your package.

Enter image description here

Campbellite answered 11/5, 2017 at 23:35 Comment(0)
D
2

clean and rebuild the solution might not replace all the dll's from the output directory.

what i'll suggest is try renaming the folder from "bin" to "oldbin" or "obj" to "oldobj"

and then try build your silution again.

incase if you are using any third party dll's those you will need to copy into newly created "bin" or "obj" folder after successful build.

hope this will work for you.

Durman answered 3/12, 2017 at 18:39 Comment(0)
C
2

No solution worked for me. I tried clean project solution, remove bin, update package, downgrade package and so on... After two hours I loaded default App.config from project with assemblies and there I changed wrong reference version from:

<dependentAssembly>
    <assemblyIdentity name="Microsoft.IdentityModel.Logging" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.5.0.0" newVersion="5.5.0.0" />
</dependentAssembly>

to:

<dependentAssembly>
    <assemblyIdentity name="Microsoft.IdentityModel.Logging" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.14.0.0" newVersion="5.5.0.0" />
</dependentAssembly>

After this I cleaned project, build it again and it worked. No warning no problem.

Crossly answered 22/8, 2019 at 12:39 Comment(0)
C
2

This question is quite old, and I had the same error message recently with Azure DevOps Yaml pipelines and Dotnet Core 3.1. The problem was somewhat different than the other answers try to solve, so I will share my solution.

I had a solution with many projects for my own nuget packages. I had by accident added version-tag in the *.csproj files like this:

  <Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <Version>1.0.0</Version>
  </PropertyGroup>

I packed the nuget packages for all projects using Yaml with a DotnetCoreCLI@2 task:

 - task: DotNetCoreCLI@2
   displayName: 'pack'
   inputs:
     command: pack
     nobuild: true
     configurationToPack: 'Release'
     includesource: true
     includesymbols: true
     packagesToPack: 'MyNugetProject1.csproj;**/MyNugetProject2.csproj'
     versioningScheme: 'byEnvVar'
     versionEnvVar: 'GitVersion.SemVer'

The problem was that the version in the *.csproj files didn't match the version in the environment variable GitVersion.SemVer (specified by input-"versionEnvVar").

After removing all <Version>1.0.0</Version>-tags in the *.csproj files the assembly/fileversion for dll was automatically assigned by the environment-variable and both nuget and dll (assembly/fileversion) would have the same version and problem was solved.

Clone answered 11/12, 2020 at 14:14 Comment(0)
F
1

Manually deleting the old assembly from folder location and then adding the reference to new assemblies might help.

Flinger answered 6/6, 2014 at 9:27 Comment(0)
A
1

I had the same issue today which prevented me from performing Add-Migration after I made changes in Entity Framework.

I had two projects in my solution, let's call them "Client" and "Data" - a class library project which held my EF models and context. The Client referenced the Data project.

I had signed both projects, and then later made changes to an EF model. After I removed the signature I were able to add the migrations, and could then signed the project anew.

I hope this can be useful for someone, sparing them of prolonged frustration..

Averroes answered 1/8, 2014 at 13:55 Comment(2)
what do you mean by: "I had signed both projects"??Reptile
IIRC then I had created a signed project so that users could verify the integrity of the program. You can read more about the concept here: learn.microsoft.com/en-us/visualstudio/ide/…Averroes
P
1

In my case the problem was between the chair and the keyboard :-)

Could not load file or assembly 'DotNetOpenAuth.Core, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=2780ccd10d57b246' or one of its dependencies.
The located assembly's manifest definition does not match the assembly reference.
(Exception from HRESULT: 0x80131040)

Two or more different assemblies wanted to use a different version of the DotNetOpenAuth library, and that would not be a problem. Furthermore, on my local computer a web.config was automatically updated by NuGet:

<dependentAssembly>
    <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
    </dependentAssembly>
    <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
</dependentAssembly>

Then I realized that I had forgot to copy/deploy the new web.config to the production server. So if you have manual way of deploying web.config, check it is updated. If you have completely different web.config for production server, you have to merge these dependentAssembly section in sync after using NuGet.

Pren answered 7/12, 2014 at 16:24 Comment(0)
H
1

I got the same error... In my case it got resolved as follows:

  • At first when the application was installed then the people here had used Microsoft Enterprise Library 4.1 in the application.
  • In previous week my machine was formatted & after that today when I built that application then it gave me an error that Enterprise Library assembly is missing.
  • Then I installed Microsoft Enterprise Library 5.0 which I got on Google as first search entry.
  • Then when I built the application then it gave me the above error i.e. The located assembly's manifest definition does not match the assembly reference.
  • After much of a search work & analysis, I found that application was referring 4.1.0.0 & the DLL in the bin folder was of the version 5.0.0.0
  • What i did was then I installed the Microsoft Enterprise Library 4.1.
  • Removed the previous reference(5.0) & added the 4.0 reference.
  • Built the application & voila...it worked.
Halette answered 29/4, 2015 at 13:10 Comment(0)
S
1

If you ever get an error like "The located assembly's manifest definition does not match the assembly reference" and if you have updated via Project > Manage NuGet Packages and Update tab in VS, the first thing you could do is try installing another version of the package after checking versions from NuGet Gallery page and running the folowing command from Package Manager Console:

PM> Install-Package YourPackageName -Version YourVersionNumber 
//Example
PM> Install-Package Microsoft.Extensions.FileProviders.Physical -Version 2.1.0

Although answer is not directly related to the package in question and it was asked way back, it is kind of generic, still relevant and hope it helps someone.

Sessions answered 15/6, 2018 at 15:14 Comment(0)
I
1

Try removing the assembly refernce from your webConfig/appConfig

 <dependentAssembly>
        <assemblyIdentity name="System.IO" publicKeyToken="B03F5F7F11D50A3A" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.3.0.0" />
      </dependentAssembly>
Illative answered 28/7, 2020 at 7:5 Comment(0)
C
1

I had the same error but in my case I was running a custom nuget package locally into another project.

What fixed it for me was changing the package version to the version requested in the error.

The package was in netstandard 2.1 and the project requesting the package was in netcore 3.1

enter image description here

Cavie answered 15/1, 2021 at 10:12 Comment(0)
F
1

In My case, None of above solutions worked - issue was caused by old .net configuration (2.0) schema defined in app.config because of which bindingRedirect was not working.

Remove xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0" from app.config or web.config, as it seems like bindingRedirect is not supported in older versions of .net framework like 2.0

enter image description here


Hopefully, this will save someone few Hours or Days.

Feleciafeledy answered 27/7, 2022 at 1:22 Comment(0)
A
1

It's not uncommon for .DLLs to report a different version using reflection's Version property in code compared to in the File Explorer's > Properies > Details tab.

Over the years I found that using this bit of powershell works better to find which version you should set your binding redirect to.

[Reflection.AssemblyName]::GetAssemblyName('C:\Source\Project\Web\bin\System.Memory.dll').Version

Major  Minor  Build  Revision
-----  -----  -----  --------
4      0      1      2

From the above I can insert (or replace) the binding redirect in my app.config file:

<dependentAssembly>
    <assemblyIdentity name="System.Memory" culture="neutral" publicKeyToken="cc7b13ffcd2ddd51"/>
    <bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2"/>
</dependentAssembly>

In that particular example the file version reported by the Details tab for System.Memory.dll was 4.6.31308.01.

Alarise answered 31/8, 2022 at 13:59 Comment(0)
M
0

I received this error message due to referencing an assembly that had the same name as the assembly I was building.

This compiled but it overwrote the referenced assembly with the current projects assembly - thus causing the error.

To fix it I changed the name of the project, and the assembly properties available through right-clicking on the project and choosing 'Properties'.

Marcel answered 12/7, 2011 at 2:24 Comment(1)
hmm, I'd keep this in mind when naming projects in the future. thanks!Reptile
G
0

I had a similar problem when attempting to update one DLL file of my web-site.

This error was occurring, when I simply copied this DLL file into bin folder over FTP.

I resolved this problem by:

  1. stopping the web-site;
  2. copying needed DLL file/DLL files;
  3. starting the web-site
Goddart answered 6/9, 2012 at 7:20 Comment(0)
F
0

In your AssemblyVersion in AssemblyInfo.cs file, use a fixed version number instead of specifying *. The * will change the version number on each compilation. That was the issue for this exception in my case.

Feuillant answered 30/7, 2013 at 5:43 Comment(1)
thanks for this. didn't know this before now!Reptile
P
0

I ran into this issue while using an internal package repository. I had added the main package to the internal repository, but not the dependencies of the package. Make sure you add all dependencies, dependencies of dependencies, recursive etc to your internal repository as well.

Piloting answered 24/1, 2014 at 16:1 Comment(1)
what's an internal package repository?? how do you add dependencies of dependencies in a project, can you give an example??Reptile
T
0

I had this problem after starting to use InstallShield. Even though the build order showed the installation project to be last it was building out of order.

I corrected this by making every other project dependent upon it - this forced the installation to build last and thereby removed my assembly mismatching. I hope this helps.

Tripos answered 22/9, 2014 at 15:50 Comment(0)
F
0

This can also occur if you are using both AssemblyInfo.cs with the AssemblyVersion tags and your .csproj file has with a different value. By either matching the AssemblyInfo or removing the section all together the problem goes away.

Fruiter answered 4/12, 2015 at 8:57 Comment(1)
yet another thing to look out for. thanks for pointing this out!Reptile
E
0

OK, one more answer. I previously created my app as 64 bit and changed the output path (Project/Properties/Build/Output/Output Path) accordingly. Recently I changed the app to 32 Bit (x86), creating a new output path. I created a shortcut to where I thought the compiled .exe was going. No matter what I changed about the source, it got the manifest not matching error. After about an hour of frustration, I happened to check the date/time of the .exe file, saw it was old obviously referencing old .dll's. I was compiling the app into the old directory and my shortcut was referencing the newer. Changed the output path to where the .exe should go, ran the shortcut and error is gone. (slaps forehead)

Edessa answered 18/1, 2017 at 23:45 Comment(0)
M
0

The problem with me was that there were old dll's dployed that were deleted in a new build. To fix it, I just checked the box to remove additional files at destination when publishing. Remove additional files at destination

Mana answered 10/1, 2018 at 16:19 Comment(0)
E
0

Had similar issue mentioned at this post "Any suggestions on how I figure out what is trying to reference this old version of this DLL file?"

Needed which assembly still refers old ODATA client 6.15.0 , the ildasm helped to narrow down for me (without base code access, only via deployed pkg at server).

Screen shot below for quick summary.

DeveloperPackge if don't have ildasm.exe https://www.microsoft.com/net/download/visual-studio-sdks

ildasm usage to resolve assembly mismatch issue

Ealasaid answered 21/6, 2018 at 22:29 Comment(0)
I
0

This same error was surfacing for me in my Unit Tests project and resulting in some failing tests. I double-checked which version of the assembly I was using in assembly explorer and checked the contents of the runtime/dependentassembly tags and realized a different version of the assembly I had been using was still being referenced there. Because this was the only directive in my tests project app.config I just tried deleting the entire app.config file, rebuilding the solution, and that did the trick! No more reference errors for me :)

Interlinear answered 25/1, 2019 at 22:11 Comment(0)
I
0

I was getting:

Could not load file or assembly 'XXX-new' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

It was because I changed the name of the assembly from XXX.dll to XXX-new.dll. Reverting name back to the original fixed the error.

Incorporation answered 18/4, 2019 at 8:45 Comment(0)
H
0

check the licenses.licx in properties of project you will find the wrong version there.... it worked for me in active report refrences

Humanist answered 22/5, 2019 at 6:59 Comment(0)
J
0

Happened to me for System.ValueTuple

Unexpected Error Could not load file or assembly 'System.ValueTuple, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.

Solved it by installing .NET Framework 4.7.2 Runtime on the machine the error occurred on. Simple and no need to add bindingRedirect, modifying GAC or downgrading NuGet packages etc.

https://dotnet.microsoft.com/download/dotnet-framework/net472

Jenelljenelle answered 29/5, 2019 at 11:35 Comment(0)
G
0

I had similar problem but no answer worked for me.

The solution that worked for me was removing publicKeyToken part from project file(YourProject.csproj) manually.

Previously it had been:

<Reference Include="Utility, Version=0.0.0.0, Culture=neutral, PublicKeyToken=e71b9933bfee3534, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>dlls\Utility.dll</HintPath>
</Reference>

After change it was:

<Reference Include="Utility, Version=1.0.1.100, Culture=neutral, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>dlls\Utility.dll</HintPath>
</Reference>

Be sure that SpecificVersion is False.

Gush answered 7/10, 2019 at 8:45 Comment(0)
B
0

Solved my issue like this with brute force.

I realised I hand multiple copies of the DLL all over the solution and two different versions.

Went into the solution in explorer, searched for the offending DLL and deleted all of them. Then added the references to the DLL back using the one version of the DLL.

Burdensome answered 16/11, 2019 at 11:37 Comment(0)
K
0

I got stumped with this for a while. I could build and run in release, couldn't in debug due to a reference that didn't match match the manifest. I must have checked the references a hundred times, and deleted all dll's. I noticed that the generated manifest in debug and release were different.

I deleted the app.manifest in my project/properties and it fixed the problem. This didn't include mention of the offending referenced dll's - so I don't know why this was causing a problem.

Kaveri answered 31/5, 2020 at 16:59 Comment(0)
C
0

Running the migrator to upgrade from using packages.config to PackageReference painlessly fixed this error for me. If you're running Visual Studio 2017 Version 15.7 or later, you can upgrade by following the steps below.

https://learn.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference#migration-steps

Here are the steps (copied from the above link):

  1. Open a solution containing project using packages.config.

  2. In Solution Explorer, right-click on the References node or the packages.config file and select Migrate packages.config to PackageReference....

  3. The migrator analyzes the project's NuGet package references and attempts to categorize them into Top-level dependencies (NuGet packages that you installed directly) and Transitive dependencies (packages that were installed as dependencies of top-level packages).

Note: PackageReference supports transitive package restore and resolves dependencies dynamically, meaning that transitive dependencies need not be installed explicitly.

  1. (Optional) You may choose to treat a NuGet package classified as a transitive dependency as a top-level dependency by selecting the Top-Level option for the package. This option is automatically set for packages containing assets that do not flow transitively (those in the build, buildCrossTargeting, contentFiles, or analyzers folders) and those marked as a development dependency (developmentDependency = "true").

  2. Review any package compatibility issues.

  3. Select OK to begin the migration.

  4. At the end of the migration, Visual Studio provides a report with a path to the backup, the list of installed packages (top-level dependencies), a list of packages referenced as transitive dependencies, and a list of compatibility issues identified at the start of migration. The report is saved to the backup folder.

  5. Validate that the solution builds and runs. If you encounter problems, file an issue on GitHub.

Cunha answered 7/4, 2021 at 0:10 Comment(0)
A
0

I was stuck in the similar issue . Unloaded the solution file and clicked on edit in csproj searched for particular dll, went to the path of the dll packages folder , found out there were two different versions of dll having same name so deleted the old one and now builded successfully.

Hope this helps somebody.

Alburga answered 28/9, 2022 at 18:58 Comment(0)
R
0

There are so many answers to this question, and since not all are relevant to my situation, I couldn't review them all in detail. So please forgive me if my answer is redundant. My situation was due to NuGet package management in Visual Studio 2012. To address it, I placed my Nuget package in a central location and checked all the project references to make sure they were pointing to this package (adding or removing them as appropriate). One caveat, when that still didn't solve the problem, I checked my Reference Paths (under the project's Properties->References->Reference Paths... or Properties->Reference Paths, depending on the project) to make sure the correct reference path was listed. This last step will not be necessary for all projects, so should probably only be used as needed.

Riccardo answered 18/10, 2023 at 15:40 Comment(0)
S
-1

Please run the code in Visual Studio debugger. Please run till you get the exception. There will be Visual Studio Exception UI. Please read the "full details" /"Show details" at the bottom of Visual Studio Exception. In Full details/Show details, it told me that one of my project (which was referring to my main project has a different version of Microsoft.IdentityModel.Clients.ActiveDirectory). In my case, my unit test project was calling my project. My unit test project and my project has a different version of Microsoft.IdentityModel.Clients.ActiveDirectory. I am getting run time error when my unit test were executing.

I just updated the version of my unit test project with the same version of main project. It worked for me.

Sollie answered 25/8, 2019 at 5:10 Comment(2)
What is "Full details"?Sergio
Please start debugging in Visual Studio. Visual Studio will throw an exception on reaching the piece of code. Please see "Show details" in the Visual Studio's Exception UI at the bottom. I also edited my answer with more details.Sollie
S
-3

Right click the reference in VS set "Specific Version" property to True.

Stupefaction answered 1/9, 2010 at 19:41 Comment(0)
P
-4

Try adding whatever's missing to the global assembly cache.

Padlock answered 1/7, 2010 at 13:59 Comment(1)
Actually, I don't get the downvotes. When a reference is missing, sometimes adding it to the GAC actually IS the answer, ASSUMING that is where the reference is pointed. I agree this answer could've been phrased as a direct response to the author's question, a link on how to get it in the GAC, but let's not penalize for a general answer -- especially with the other branching on here, already. I see SO as a bunch of possible answers to the error type, not just the specific scenario. And they don't have over 50 rep, so they can't add a comment to the question or posts (which IMHO should change).Radial

© 2022 - 2024 — McMap. All rights reserved.