Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference changed to wrong version of assembly #3415

Closed
josefblaha opened this issue Aug 3, 2017 · 9 comments
Closed

Reference changed to wrong version of assembly #3415

josefblaha opened this issue Aug 3, 2017 · 9 comments
Labels
Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. Resolution-Wont Fix

Comments

@josefblaha
Copy link

During F# project build, an assembly reference could be changed to a wrong version of the same assembly from Reference Assemblies.

Repro steps

  1. Create a new F# console app project targeting .NET 4.6.1.
  2. Install System.Net.Http NuGet package version 4.3.2. Note that it contains System.Net.Http.dll with assembly version 4.1.1.1.
  3. Build the project.

Expected behavior

The reference to System.Net.Http assembly should still point to the correct assembly in packages\System.Net.Http.4.3.2\lib\net46.

Actual behavior

The reference was changed to point to C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Net.Http.dll, which has assembly version 4.0.0.0 (it's older). This file is also copied to the project output directory.

Known workarounds

None.

Related information

Win10 1511, .NET 4.6.1, VS 15.2 (26430.16), Visual F# 4.1

When I do the same with C# console app, it behaves as expected keeping the right assembly.

@dsyme dsyme added Area-IDE Project System Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. labels Aug 5, 2017
@idg10
Copy link

idg10 commented Aug 17, 2017

This looks like another instance of an issue that has been around for at least a couple of years now, which the NuGet and F# teams both seem to think that that other team will fix.

This was reported back in September of 2015 in https://github.com/dotnet/corefx/issues/3103 as a Core FX bug, then shortly after that in October 2015 as a NuGet bug in NuGet/Home#1510 - both describe it as a problem with System.Numerics.Vectors but it looks like the broader issue that if a NuGet package contains a DLL with a Simple Name that is the same as an existing framework assembly, you end up with a reference to the framework assembly even if the version in the NuGet package is newer.

This seems to have been around as a bug for a very long time, but it is becoming increasingly problematic now that we're seeing more out-of-band releases of updates to framework DLLs via NuGet.

Unfortunately there seems to be a bit of a muddle on who should fix it. The timeline so far as far as I can see is:

So in short, @dsyme said back in February 2016 that F# should fix this (even though it looked like NuGet also had an issue, and a NuGet fix might fix it for more people sooner). But the relevant issue #939 got closed without it apparently being fixed.

We're going to start seeing a lot more examples of this I think, with the way .NET is evolving - it's now quite common to come across newer versions of assemblies that are also in the reference assemblies.

@dsyme
Copy link
Contributor

dsyme commented Aug 17, 2017

@idg10 Is there a workaround by using a direct reference to the DLL in the package?

@dsyme
Copy link
Contributor

dsyme commented Aug 17, 2017

So the workaround would be "delete the reference and add a direct DLL reference to packages\System.Net.Http.4.3.2\lib\net46\System.Net.Http.dll". However I don't know if that is robust under further package add/remove

Another workaround is to use Paket.

@idg10
Copy link

idg10 commented Aug 18, 2017

If you modify references directly in the .fsproj that came from a NuGet reference, Visual Studio seems to overwrite them any time you make any sort of NuGet change - it seems to reset all NuGet-originated references.

It's possible I'm not doing exactly what you've suggested. I'm not 100% sure what a "direct DLL reference" really is. Looking at the docs for the <Reference> element at https://docs.microsoft.com/en-us/visualstudio/msbuild/common-msbuild-project-items the only way I see to specify the exact location of a file is through <HintPath>

Is that what you meant? If so, then I can confirm that Visual Studio will delete the <HintPath> the next time you do add or update any package in the project.

I'm looking into Paket - a few people have mentioned it. But where I really want to get to is to be able to use <PackageReference> - the only reason I have a reference to System.Net.Http at all is that my F# project uses a NuGet package that in turn depends on it. In C# projects in the same solution that are using the new type of project file I don't have any direct references to System.Net.Http at all because the transitive reference handling picks it up automatically. Will a move to Paket make it harder to migrate to the new project file approach? (The main thing stopping me using the new format already is that if you open an F# project with an MSBuild 15 style .fsproj IntelliSense starts reporting spurious errors.)

@forki
Copy link
Contributor

forki commented Aug 18, 2017 via email

@idg10
Copy link

idg10 commented Aug 18, 2017

So, 2 hours of attempting to convert to Paket and it appears that for some reason when I move my project over to that, Paket adds two separate references to System.Net.Http each in Choose/When/ItemGroup sections conditional on $(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v4.7', one with just a single <Reference> to System.Net.Http and one that shares the group with System.Net, System.Net.Http.WebRequest, System.Runtime.Serialization and Microsoft.Rest.ClientRuntime. Presumably this has something to do with me using a couple of Azure management APIs.

And even after all this I'm getting this warning:

warning MSB3243: No way to resolve conflict between "System.Net.Http, Version=4.1.1.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Choosing "System.Net.Http, Version=4.1.1.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" arbitrarily.

And this despite my paket.dependencies containing this specific version reference nuget System.Net.Http 4.3.2 (and the paket.references for my F# project also includes System.Net.Http explicitly).

If in VS's Solution Explorer I delete one of the relevant entries under the References node for the project, and change the other to require a specific version, the warning goes away, but then I'm back in much the same situation as I was with the NuGet workaround: you can make the problem go away by editing the .fsproj but the next time you update your package references, the workaround may be overwritten.

So unfortunately Paket doesn't appear to solve my particular instance of this problem. I don't have a good workaround either with NuGet or Paket.

Update: and yes, the manual edit does indeed get overwritten next time you change anything in Paket.

Update 2: although I've now worked out what was making it do that. I've created an issue over at Paket: fsprojects/Paket#2629 - this means I can now use Paket to work around this issue, but the bug described in this issue remains if you can't use Paket.

@forki
Copy link
Contributor

forki commented Aug 18, 2017 via email

@forki
Copy link
Contributor

forki commented Aug 18, 2017

see fsprojects/Paket#2628

@cartermp cartermp added this to the 16.0 milestone Aug 29, 2018
@cartermp cartermp modified the milestones: 16.0, 16.1 Feb 21, 2019
@cartermp cartermp modified the milestones: 16.1, 16.2 Apr 23, 2019
@cartermp cartermp modified the milestones: 16.2, Backlog Apr 30, 2019
@cartermp cartermp removed this from the Backlog milestone Aug 15, 2020
@cartermp
Copy link
Contributor

Since this is a legacy project system + packages.config issue, with both technologies being deprecated due to intractable problems with their design, this will be closed. I'd encourage any issues of this sort with SDK-style projects to be filed here if they exist: https://github.com/dotnet/project-system (though I doubt they do given how robust it is and how robust packagereference is)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. Resolution-Wont Fix
Projects
None yet
Development

No branches or pull requests

5 participants