Project References DLL version hell

49,786

Solution 1

To overcome this, I removed EVERY reference, then added them all back in again. I don't know why this is the solution.

It is possible that in one project a DLL was incorrect, and it is this incorrect DLL that was pulled through by visual studio and used.

Edit: Other times this error has occurred is due to a DDL (A) being referenced in the current project also being referenced by another DLL (B). Not rebuilding this other DLL (B) seems to prevent VS from referencing the correct version of DLL (A) in the current project and thus it brings through an older version of DLL (A).

Solution 2

To avoid the dll hell I would recommend you to create a lib folder inside your project and put all shared assemblies in this folder. Next you Add References only from this folder. This way your project is self contained and you know exactly where it is picking the references from. If you want to update some assembly with a newer version you copy it to the lib folder and rebuild your project.

Also make sure you don't the referenced assemblies into the GAC as they might be picked up first.

Solution 3

There are few options that you can try.

  1. Compile the project and see in output window to verify the assembly path where it is referred from exactly.
  2. Delete Obj folder before you recompile it.
  3. Close and reopen the Visual Studio since VS has some weird behavior to keep the cache to hold Dll references.
  4. If you still see the problem, use this tool to check the reference assembly where it comes from really. Process Explorer.

Solution 4

Have you tried adding the reference as a Project Reference? i.e. Add Reference... -> Projects tab -> Select your project

Solution 5

We (and, as the only .NET developer on our team, by that I mean I) had the exact same problem. I traced it down to a referenced dll, which in turn AGAIN references the dll suffering from versionitis. It seems that because I wasn't updating all the references which in turn reference the dll, it was replaced by an older version at some point during the build process.

One of the symptoms I experienced was that when I am in the code editor, the new class I added to the referenced project would be coloured appropriately, but when I hit Build, it changes back to black and I get a message saying the class does not exist (along with a very sarcastic "Ar you missing an assembly reference?"). This led me to believe that the problem has to happen during the Build phase.

I would therefore suggest building any and every other project that points to this DLL and re-add their references too.

Share:
49,786
Mr Shoubs
Author by

Mr Shoubs

Hello, A Software Developer for BTC Solutions, spend my day keeping a shipload of pirates in order. http://uk.linkedin.com/pub/daniel-shoubridge/13/338/470/

Updated on September 12, 2020

Comments

  • Mr Shoubs
    Mr Shoubs over 3 years

    We're having problems getting visual studio to pick up the latest version of a DLL from one of our projects.

    We have multiple class library projects (e.g. BusinessLogic, ReportData) and a number of web services, each has a reference to a Connectivity DLL we've written (this ref to the connectivity DLL is the problem).

    We always point references to the DLL in the bin/debug folder, (which is where we always build to for any given project) and all custom DLL references have CopyLocal = True and SpecificVersion = False

    ReportData has a reference to business logic (which also has a reference to connectivity - I don't see why this should cause a problem, but thought it is worth mentioning)

    The weird thing is, when you click "Add Reference" and browse to Connectivity/bin/debug - you hover the mouse over the DLL file, the correct (latest) version is shown (version and file version are always incremented together), but when you click ok, a previous version number is pulled though. Even when I look in the current projects debug folder (where copy local would put the DLL after compiling) that shows the latest version number. - NO WHERE does can I find the previous version of the DLL outside of visual studio, but in that project references it has the old version - even though the path is correct.

    I'm at a loss as to where it might be getting the old versions from. Or even why it wants that one.

    This is possibly the most frustraighting problem I have ever come across.

    Does anyone know how to ensure the latest version is pulled through (preferably automatically or on compile).

    EDIT:

    Although not exactly the scenario I'm dealing with I was reading this article and somewhere it mentions about CLR ignoring revision numbers. Understandable (even though this hasn't been a problem before - we're on revision 39), so I thought I would update the build number, still didn't work. In a vain attempt I though I would update the minor version number and see if that made any difference.

    I'm not saying this is the answer as I have to check quite a few things first, but on the face of it, this seems to have solved my problem...

    Further edit: In other class libraries this seems to have solved the problem, however in a test windows application it still pulls a previous version through :(

    If I increment the minor version number again, the same problem come back and I am left with the wrong version being pulled though.

    Further Edit - I created an entirly new project, added a reference and still had the exact same problem. This suggests the problem is restriced to the project I am referencing. Wish I knew why!

    Anyone had this problem before and know how to get around it?

    HELP!

  • aaddesso
    aaddesso about 14 years
    +1, ...and make sure to tick the local option for each shared reference inside Visual Studio.
  • Mr Shoubs
    Mr Shoubs about 14 years
    Just tried that, but it doesn't work - a previous version is still being pulled in.
  • Mr Shoubs
    Mr Shoubs about 14 years
    It was a good idea, but didn't work :( what possible places could it be getting this previous verion from? I triple checked I copied the correct file.
  • Mr Shoubs
    Mr Shoubs about 14 years
    Unfortuanly that isn't possible in our scenario, we have to reference the DLL files. (I wish this wasn't the case)
  • Mr Shoubs
    Mr Shoubs about 14 years
    I'd vote for this on style, but I've not got 15 rep points yet. 1 - shows correct path 2 - doesn't seem to make any difference at all 3 - already done, sometimes this does solve some problems with compilation, but not this problem 4 - I can't find out where in process explorer it tells me this
  • TrueWill
    TrueWill about 14 years
    Is the assembly listed in the .NET tab of Visual Studio’s Add Reference dialog? This is not the same as the GAC. If so, even if you reference an assembly through the Browse tab VS may use the Registry to find the file. This has cost me hours. I really wish Microsoft would give developers full control over the build, and fail the build if an assembly is not found (rather than trying to find it).
  • sankar
    sankar about 14 years
    1. I guess I forgot to mention this, compile and run the application and you can see where it is loaded from in output windows. 2. It is best to keep in the shared folder as Darin mentioned. So that, you can remove the bin and obj folder to always regenerate the executable file to make sure that we run with fresh copy of application. 4. You mentioned that it picks the wrong assembly from somewhere right? Using this tool, you can just view the referenced assemblies of an application and see where it is loaded from and its version number and etc in runtime.
  • sankar
    sankar about 14 years
    5. Additionally, open your project file in Notepad and see if there is any hardcoded version number or hintpath is there. If yes, remove them and add correct version number.
  • Mr Shoubs
    Mr Shoubs about 14 years
    It isn't in the GAC but it is in the .net tab... and personally I think they should fail the build if the assembly is the wrong Major version.
  • Mr Shoubs
    Mr Shoubs about 14 years
    There is: <Reference Include="VHC.Connections, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>..\..\..\vhc.server.solution\vhc.connections\Tags\‌​v_3_0_0_5\bin\Debug\‌​VHC.Connections.dll<‌​/HintPath> </Reference> but changing it makes no difference
  • sankar
    sankar about 14 years
    Ok, did you use Process Explorer utility?
  • Mr Shoubs
    Mr Shoubs about 14 years
    In process explorer I can't see where you can find referenced assemblies - I right click on the app, click properties, nothing to do with refereced assemblys in there...
  • Thomas
    Thomas about 14 years
    If no version of the assembly is in the GAC and you have removed the reference to the library in your project's Reference's list and re-added it to point only to the dll in the /lib folder, there is no way the version could be anything other than what is in that folder unless you did not do that same procedure for all projects in the solution that have a reference to the DLL. Each project that needs to reference that DLL needs to use a local /lib folder.
  • TrueWill
    TrueWill about 14 years
    @Mr Shoubs - I'm with you on this one. Try removing the Registry key (after making a backup) to remove the assembly from the .NET tab. See support.microsoft.com/kb/306149
  • Mr Shoubs
    Mr Shoubs about 14 years
    Interesting - though I don't see how it helps my problem? I thought I would give it the benefit of the doubt, but that path doesn't exist in my registry - I get to HKCU\Software\Microsoft, then there is no .Net datafolder...
  • Wagner Silveira
    Wagner Silveira over 13 years
    I pretty sure that this is not the case, but since you're coming too close to the end of the tunnel, have you confirmed that you're looking at the assembly version instead of the file version? Can you confirm that file version and assembly versions are the same? Also, can you include a new method in the assembly and find if the new method comes through, just for test?
  • Zach Young
    Zach Young over 12 years
    I think this works because when the reference is added to the project (through Visual Studio) the version metadata is recorded in the <Reference/> line. I'm working with the same problem and found that unloading the project, finding the reference and manually changing the version info allowed the project to "find" the newer-versioned DLL.
  • Dave Black
    Dave Black over 11 years
    If there is a Policy redirect for the .dll defined in the GAC (even though the assembly is not in the GAC), it will probe for this first, then probe in the local bin and then probe in the GAC.
  • Dave Black
    Dave Black over 11 years
    If you enable the Fusion assembly bind logging, make sure to disable it after you are done debuggin the assembly loading problem!
  • Sam Jones
    Sam Jones about 8 years
    Worked for me, i deleted all obj and bin folders, removed reference between projects, cleaned, rebuilt, re-added references. Booyaa.
  • Ammar Khan
    Ammar Khan over 7 years
    @smirkingman In my case it is under C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root. I deleted everything from Temporary ASP.NET Files and do a clean projec but it still trying to load from the same location. Any thoughts
  • revobtz
    revobtz over 6 years
    Worked for me! Also if you are working with a publish folder it will be god to delete all contents before the publish to ensure the files are being adde new instead of replaced!.
  • Mr Shoubs
    Mr Shoubs over 6 years
    @revobtz - if you are using file publish, I think there is an option in setting (file publish options) to automatically "delete all existing files prior to publish"
  • revobtz
    revobtz over 6 years
    @MrShoubs Yes I knew about that already, but sometime people doesn't know about this. So I just want them to ensure to get the new files instead of replace but thanks for the comment it may help others!