4
votes

After updating .NET Framework NuGet packages that my solution references to last prerelease version. I've got a building error:

Multiple assemblies with equivalent identity have been imported: 'C:\Projects\RP\packages\System.Reflection.4.1.0-beta-23516\lib\net46\System.Reflection.dll' and 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.6\Facades\System.Reflection.dll'. Remove one of the duplicate references.

I can't figure out how resolve this issue. If I remove System.Reflection using NuGet it throws reference error exception, it wants System.Reflection v.4.1.0.0.

Could not load file or assembly 'System.Reflection, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

How can I remove a duplicate?

2
Did you check your .csproj file if 4.1.0 is still used there? You can open the .csproj file with notepad or notepad++ and look if the old version is still named there. - Marleen Schilt
Yep, I also uninstalled tried to uninstall all .NET Framework packages, nothing helps. - AsValeO

2 Answers

5
votes

The problem was solved by changing this line in app.config:

<bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />

to

<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />

Managing .NET Framework packages in Visual Studio projects is messy. Information about references exists in .csproj / .vbproj, app.config, packages.config.

2
votes

You can also just grab the system.reflection 4.1.0.0 from Nuget rather than reverting back to 4.0.0.0.

Version 4.1.0.0 is in it's own Nuget Package, which is why it tends to be confusing.

I actually prefer this way, because if you run a nuget restore, any nuget packages that depend on System.Reflection 4.1.0.0, will revert any changes you made to your app.config.

Meaning, if you change your reference to 4.0.0.0, it'll revert back to 4.1.0.0 on a nuget restore.