question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong assembly is being referenced in solution

See original GitHub issue

Wrong assembly is being referenced in solution

When trying to reference 1.0.4. version of an assembly - 1.0.1 version of file is being used… Despite the fact, that project settings are pointing to the correct DLL. As the result - the solution is still compiled with 1.0.1 version.

General

Specs

OS:

  • OS Name Microsoft Windows 10 Enterprise
  • Version 10.0.16299 Build 16299

VS:

  • Microsoft Visual Studio Professional 2017
  • Version 15.9.7
  • VisualStudio.15.Release/15.9.7+28307.423
  • Microsoft .NET Framework
  • Version 4.7.02556

dotnet --version

  • 2.2.104

Prerequisites

Checkout the solution from my repo:

https://github.com/pavlexander/dotnetbugs/tree/master/Bugs/12032019_WrongAssemblyLoaded

Steps to reproduce

  1. Open the solution in VisualStudio
  2. Right click on project, “Add -> Reference”.
  3. Browse for file in directory: “…12032019_WrongAssemblyLoaded\WrongAssemblyLoaded\DebugTests.Common.NugetWithPdb.1.0.4\lib\netstandard2.0\DebugTests.Common.NugetWithPdb2.dll” Proceed with adding of a reference. Note that file from 1.0.4 is selected.
  4. Right click on project, click “Edit WrongAssemblyLoaded.csproj”
  5. Verify that correct assembly is specified:
  <ItemGroup>
    <Reference Include="DebugTests.Common.NugetWithPdb">
      <HintPath>DebugTests.Common.NugetWithPdb.1.0.4\lib\netstandard2.0\DebugTests.Common.NugetWithPdb2.dll</HintPath>
    </Reference>
  </ItemGroup>
  1. Now, in VisualStudio, expand the tree of the project -> Dependencies -> Assemblies, find the assembly that you referenced and check the path.

Expected result:

Assembly from 1.0.4 folder is used

Actual result:

…\dotnetbugs\Bugs\12032019_WrongAssemblyLoaded\WrongAssemblyLoaded\DebugTests.Common.NugetWithPdb.1.0.1\lib\netstandard2.0\DebugTests.Common.NugetWithPdb.dll

And this is the issue. Assembly of version “1.0.1” is used in project, despite even the fact that in project settings “1.0.4” version is specified. If you try and build the solution now, in the output folder you will also see the “1.0.1” version. I don’t think this is related to Visual Studio in any way. Because, even if you try to use the dotnet build command directly - it will also put the same wrong dll into an output directory.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
MrM40commented, Apr 5, 2023

@nguerrera: IT WORKS! 😃

Lucky if found this thread! Could just as well have taken me weeks, months or never to solve this…scary thought! Very frustrating the path you specify in the project file is not respected. Think this guy had the same problem, but as usual it’s a waste of time to report anything on developercommunity. https://developercommunity.visualstudio.com/t/assembly-reference/483348

Running VS 2022 (64-bit) - LTSC 17.0Version 17.0.15 / .NET SDK 6.0.402

1reaction
nguerreracommented, Jun 5, 2019

Try adding this to .csproj:

<PropertyGroup>
  <AssemblySearchPaths>{HintPathFromItem};{TargetFrameworkDirectory};{RawFileName}</AssemblySearchPaths>
</PropertyGroup>

This removes CandidateAssemblyFiles that will find assemblies in the None and Content items, which for sdk projects will include all files under the csproj by default.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Net picking wrong referenced assembly version
I greped the solution folder for that version number and couldn't find a single reference. I double checked the text of the .csproj...
Read more >
MSB3277: Found conflicts between different versions of ' ...
This error occurs during a build when more than one version of the same dependent assembly is referenced in a build of the...
Read more >
Assembly reference loaded from wrong file path
I've a solution with 27 projects. 12 of those projects do reference external assemblies from a specified directory (copy local = true).
Read more >
the type is defined in an assembly that is not referenced error
This error message appears when a class or type that you are trying to use in your code is not properly referenced in...
Read more >
Assembly Has a Higher Version Than Referenced .NET Error
Solution. This error indicates that there is a version mismatch between what is referenced by the assembly (<Y.Y.Y.Y>) and what the project ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found