.Net picking wrong referenced assembly version
Asked Answered
F

23

168

I just copied an existing project to a brand new machine to start developing on it and have run into a problem with the version of one of my referenced assemblies (a telerik DLL as it happens).

The project originally referenced an older version of the assembly (lets call it v1.0.0.0). My new machine has the latest version of the assembly installed, so I thought I'd updated it (lets call the new version v2.0.0.0).

Now here's the problem: If I copy the old v1.0.0.0 dll to the project folder and add it as a reference, the web site launches without a problem. If I delete that reference (and also delete the old DLL from my system) and add the new version (v2.0.0.0), the page shows the following exception:

Could not load file or assembly 'XXXXXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=121fae78165ba3d4' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Clearly, the code is looking for the out of date version and can't find it. But why?

I greped the solution folder for that version number and couldn't find a single reference. I double checked the text of the .csproj file and found the version correctly shows the latest version and the HintPath correctly shows the path to the new DLL. Furthermore, because I didn't install the old DLL on the system it doesn't show up in my GAC (though v2.0.0.0 does, as expected).

I then enabled the fusion log viewer to try to figure out why it's looking for that old version, but no luck:

Assembly Load Trace: The following information can be helpful to determine why the assembly 'XXXXXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=121fae78165ba3d4' could not be loaded.


=== Pre-bind state information ===
LOG: User = MyComp\me
LOG: DisplayName = XXXXXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=121fae78165ba3d4
 (Fully-specified)
LOG: Appbase = file:///d:/My Documents/Visual Studio 2010/Projects/CoolProj/WebApp/
LOG: Initial PrivatePath = d:\My Documents\Visual Studio 2010\Projects\CoolProj\WebApp\bin
Calling assembly : WebApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: d:\My Documents\Visual Studio 2010\Projects\CoolProj\WebApp\web.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: XXXXXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=121fae78165ba3d4
LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/90233b18/10d54998/XXXXXX.DLL.
LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/90233b18/10d54998/XXXXXX/XXXXXX.DLL.
LOG: Attempting download of new URL file:///d:/My Documents/Visual Studio 2010/Projects/CoolProj/WebApp/bin/XXXXXX.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

All it says it that it starts by looking for that old assembly. I have tried to find a solution online and saw this similar SO question, but it seems to be the exact opposite of my problem. That questioner's program was finding the wrong DLL instead of the referenced one. Whereas my problem is that the program is mysteriously looking for the wrong DLL and unable to find it when the right one can be found locally in the bin folder and in the GAC.

Why is mine looking for the old version? Where else can I search to find this bad reference?

Freak answered 15/11, 2010 at 19:13 Comment(0)
W
177

My guess is that another assembly you are using is referencing the old dll. Are you familiar with all of the other project references being used and do any of them have a reference to the Telerik dlls?

Can you put in a binding redirect in your web.config file like this?

<dependentAssembly>
 <assemblyIdentity name="Telerik" publicKeyToken="121fae78165ba3d4"/>
 <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
</dependentAssembly>
Weak answered 15/11, 2010 at 19:43 Comment(9)
Thank you! The dependent assembly change got it working. I should mention, though, that there weren't any other projects in the solution or other DLLs referencing that Telerik DLL (I also greped the whole folder just to double check). Still, I can't argue with success!Freak
I've had all kinds of issues similar to this with different versions loading/not loading. Another trick you can try is to manually delete all of the files in your C:/WINDOWS/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/90233b18/10d54998 folder. Sometimes when recompiling web sites, ASP.Net doesn't clean that folder out because of some file locks and those dlls could be hanging on to old references. It's worth a shot, I know it's worked for me in the past.Weak
You solved a related problem for me - thanks! An inherited form in my C# application wouldn't open in the designer because it was looking for an old version of a reference. Turns out another reference had originally been built while referencing that old version of the problem reference.Colfin
If you are wandering about the syntax: msdn.microsoft.com/en-us/library/0ash1ksb.aspxImportance
Thanks Chris! You solved my problem here: https://mcmap.net/q/55960/-dll-versioning-error/7850Shelli
You can also look in your App.config or web.config and see if existing <dependentAssembly> entries are causing the problem.Dupion
+1 In my case it was an assembly with lower target framework. Thanks.Etruria
In my case somehow Web.config file was simply missing and I get the above error.Rayraya
That was a fun ride. Didn't include the config file in the installer output.Despicable
P
38

I tried most of the answers but still couldn't get it to work. This worked for me:

right click on reference -> properties -> change 'Specific Version' to false.

enter image description here

Hope this Helps.

Peptonize answered 28/6, 2013 at 17:14 Comment(2)
That's what voting the +1 means.Paternoster
But sometimes the simple upvote just doesn't sufficiently sum up how happy and relieved the answer makes you - after having spent hours and hours trying to fix a dumb issue that shouldn't even be an issue, and you try googling it a different way, come across a different answer than you tried before, and boom! it works now! After all that, sometimes simply pressing the upvote button doesn't do justice to that overwhelming feeling of, dude, you really bailed me out of this one.Suitable
S
28

I'm with Chris Conway on this one (upvoted him). The problem is that you are referencing one of the telerik assemblies in your project which references another one that isn't there.

First thing: I wouldn't install ANY vendor (ie: telerik) assemblies into the GAC. Telerik's stuff is compiled down to just two assemblies anyway (telerik.web.design and telerik.web.ui). Just deploy those with the application.

Second, in each of your .proj files (like .csproj) there is going to be a <reference include..> which points to the Telerik.Web.UI file. This normally contains a version number. Make sure the assembly you put in the bin folder matches that version.

Third, make sure ALL of your projects use the latest assembly. Also make sure they are grabbing the assembly from a local path instead of the GAC. (I really really don't like the GAC. It has caused no end of issues on some projects I've been on). We typically have an "Assemblies" folder that all projects use for external assembly references.

Fourth, visual studio automatically searches your gac everytime a web site project is loaded and retargets the assembly locations if it finds something in the gac. I can't remember if it ever does this for web application projects, but I haven't had the issue in a long time with those. This can cause similar issues during deployment.

Fifth, you can rebind version numbers for assemblies in the web.config. In the runtime/assemblybinding section you can use something like the following which takes every telerik assembly deployed in 2008 forward and points it to a very particular version:

  <dependentAssembly>
    <assemblyIdentity name="Telerik.Web.UI" publicKeyToken="121fae78165ba3d4" />
    <bindingRedirect oldVersion="2008.0.0.0-2020.0.0.0" newVersion="2010.02.0713.35" />
  </dependentAssembly>
Spurn answered 15/11, 2010 at 19:56 Comment(1)
I meant "feel", that's been bothering me for months now :)Freak
V
7

Try:

  • cleaning temporary project files
  • cleaning build and obj files
  • cleaning old versions installed at C:\Users\USERNAME\.nuget\packages\

That worked for me.

Vintner answered 9/8, 2016 at 20:22 Comment(2)
Cleaning the C:\Users\USERNAME\.nuget\packages\ directory was what I was missing. Thanks a lot!Sherillsherilyn
for clean old nuget version, in windows based computer, ckuck Start and search for "run" > copy& paste "%userprofile%\.nuget\packages" - this will open nuget versions folderExtend
M
5

This isn't a clear answer as to why, but we had this problem, here's our circumstances and what solved it:

Dev 1:

Solution contains Project A referencing a NuGet Package, and an MVC project referencing Project A. Enabled NuGet Package Restore, then updated the NuGet package. Got a runtime error complaining the NuGet lib can't be found - but the error is it looking for the older, non-updated version. Solution (and this is ridiculous): Set a breakpoint on the first line of code in the MVC project that calls Project A. Step in with F11. Solved - never had a problem again.

Dev 2:

Same solution and projects, but the magic set breakpoint and step in solution doesn't work. Looked everywhere for version redirects or other bad references to this Nuget package, removed package and reinstalled it, wiped bin, obj, Asp.Net Temp, nothing solved it. Finally, renamed Project A, ran the MVC project - fixed. Renamed it back to its original name, it stayed fixed.

I don't have any explanation for why that worked, but it did get us out of a serious lurch.

Monosyllable answered 5/11, 2013 at 20:26 Comment(0)
M
4
  1. Go to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG
  2. Find machine.config file
  3. open in notepad
  4. find conflict dll
  5. Remove this and save.

compilation assemblies

addassembly=dllName,Version=1.0.0000.0000 Culture=neutral,PublicKeyToken="QWEWQERWETERY"

assemblies compilation

works for me.

Multiplicand answered 14/3, 2013 at 2:50 Comment(1)
I also discovered this nightmare - even if you remove assembly from GAC it leaves wrong version references in "C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config"Anstice
A
3

Do you have any other projects in that solution ?(may be another project was referencing an old version) Usually in VS, dll dependency spans all projects in the solution.

Argyrol answered 15/11, 2010 at 19:48 Comment(1)
No other projects in solution and no other referenced DLLs that reference telerik. I'm only referencing MS DLLs ala System.*Freak
G
3

I had a similar issue and I had to delete everything from the bin and obj folders and rebuild to get past my issue. Hope this helps.

Gavriella answered 19/1, 2018 at 16:18 Comment(0)
B
2

My problem was that the old assemblies were in the _bin_deployableAssemblies folder under the Web Application. This meant the old assemblies were overwriting the GAC assemblies when building the project.

Bosley answered 27/6, 2012 at 0:31 Comment(0)
C
2

In case is saves someone else 3 hours... my case was a bit different. My code used DevExpress v11.1 v11.1.4.0. I had it all referenced correctly in my code. But .net memory profiler installed DevExpress v11.1 v11.1.12.0 in the GAC. In fact it wasn't the components I referenced but the ones they referenced internally that failed. Try as I might, the GAC is always checked first. It compiled and ran fine but I couldn't view the win forms designer and the stack trace was no help at all. Finally uninstalled .net memory profiler and all was restored.

Ciaracibber answered 30/7, 2013 at 6:58 Comment(0)
R
2

This error was somewhat misleading - I was loading some DLLs that required x64 architecture to be specified. In the .csproj file:

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release-ABC|AnyCPU'">
    <OutputPath>bin\Release-ABC</OutputPath>
    <PlatformTarget>x64</PlatformTarget>
</PropertyGroup>

A missing PlatformTarget caused this error.

Ruffina answered 30/10, 2018 at 16:21 Comment(0)
K
2

I was getting:

Could not load file or assembly 'XXX-new-3.3.0.0' 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-3.3.0.0.dll. Reverting name back to the original fixed the error.

Kele answered 18/4, 2019 at 8:43 Comment(1)
Yep - included a version in the name in our common assembly library to avoid naming issues in source control. Changed the name back and manually updated the references / hint paths and it all worked.Capillarity
D
1

If you are experiencing this problem when testing and/or debugging the application from the Visual Studio environment (ASP.NET Development Server), it is necessary to delete all temporary files on the development website folder. To know where that folder is, look for the ASP.NET Development Server icon on the Windows tray icon (it should have a title like this: ASP.NET Development Server - Port ####), right click the icon and select Show Details; thn, the field Physical path will tell you what the temporary folder is, all items there should be deleted to solve the problem. Build and run again the website and the problem should be solved (again, solved for the Development Environment).

Destructive answered 22/2, 2013 at 20:27 Comment(0)
W
1

I had the same problem with different assemblies referencing different versions of Newtonsoft.json. The solution that worked for me was running update-package from Nuget Package Manager Console.

Wivern answered 25/9, 2015 at 17:54 Comment(0)
R
0

Its almost like you have to wipe out your computer to get rid of the old dll. I have already tried everything above and then I went the extra step of just deleting every instance of the .DLL file that was on my computer and removing every reference from the application. However, it still compiles just fine and when it runs it is referencing the dll functions just fine. I'm starting to wonder if it is referencing it from a network drive somehwere.

Reviere answered 28/12, 2012 at 16:57 Comment(0)
S
0

I had the same message when switching between two versions of an application that referenced different versions of the same DLL. Although I was testing in different folders I accidentally copied the newer version over the older version.

So the first thing to check is the version of the referenced DLL in the application's folder. Just in case.

Syllable answered 7/2, 2014 at 13:15 Comment(0)
S
0

Maybe this helps or maybe not. I cleaned my debug and release versions then I renamed the OBJ folder. This finally got me thorugh. Previous steps were basically project removing references and them adding them back in at the project properties.

Surgeonfish answered 24/9, 2014 at 11:46 Comment(0)
B
0

In My Visual Studio 2015, I ensured that the offending Visual Studio Project's Reference Paths List is empty:

enter image description here

Beeck answered 27/2, 2018 at 18:59 Comment(1)
You posted the exact same answer to 2 different questions?Recurrence
L
0

This is what worked for me:

I was using the Microsoft.IdentityModel.Clients.ActiveDirectory version 3.19 in a class library project but only had version 2.22 installed in the actual ASP.NET Web Application project. Upgrading to 3.19 in the web app project got me past the error.

Labana answered 1/5, 2018 at 0:40 Comment(0)
M
0

In my case i had 3 projects, 1 main project and 2 sub projects referenced by main project.. So i updated the main project, leaving out sub project. That's where the conflict was. After i updated all my project everything worked just fine.

Masefield answered 19/6, 2018 at 23:18 Comment(0)
L
0

In VS2017, have tried all the above solution but nothing works. We are using Azure devops for versioning.

  1. From the teams explorer > Source Control Explorer

enter image description here

  1. Select the project which driving you nuts for a long time

  2. Right click the branch or solution > Advanced > get specific version

enter image description here

  1. Then make sure You have ticked the checkbox of overwrite files as per screenshot

enter image description here

Lachance answered 25/2, 2019 at 2:23 Comment(0)
O
0

In my case, I accidentally chose the wrong version of the Telerik package from nuget, which nuget then replaced every package i referenced with the incorrect version. It then inserted a binding redirect to the incorrect version so that even after I replaced everything with the correct version, it was still looking for the incorrect version.

Oisin answered 11/10, 2019 at 19:2 Comment(0)
R
0

I lazily let Visual Studio's Nuget Package Manager resolve the thing for me in two steps:

  1. Remove all contents from <runtime><assemblyBinding in Web.config

  2. Use the following command in Package Manager Console:

    Add-BindingRedirect

Ruin answered 30/8, 2023 at 18:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.