Skip to content

Wrong assembly is being referenced in solution #3301

Open
@pavlexander

Description

@pavlexander

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.

Activity

karelz

karelz commented on Mar 30, 2019

@karelz
Member

@nguerrera any idea where to route it?

karelz

karelz commented on Jun 5, 2019

@karelz
Member

@nguerrera @dsplaisted can you please help route it?

nguerrera

nguerrera commented on Jun 5, 2019

@nguerrera
Contributor

This will be due to none item globbing and “candidate assembly files” winning over hint path.

Karel, you can move this to dotnet/sdk and I'll go over the options to avoid this tomorrow.

transferred this issue fromdotnet/coreon Jun 5, 2019
nguerrera

nguerrera commented on Jun 5, 2019

@nguerrera
Contributor

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.

added this to the Discussion milestone on Jun 5, 2019
MrM40

MrM40 commented on Apr 5, 2023

@MrM40

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @nguerrera@karelz@MrM40@pavlexander

        Issue actions

          Wrong assembly is being referenced in solution · Issue #3301 · dotnet/sdk