简体   繁体   中英

System.Reflection multiple assemblies error after update

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?

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM