Build error "An item with the same key has already been added."
See original GitHub issue“dotnet build” throws an error when project.lock.json contains assemblies with the same name in different packages. While this seems logical on one side, it is quite hard to debug these issues.
My biggest concern is that this is a common problem in Microsoft packages as well. Packages like “Microsoft.Net.Http” and “System.Net.Http” contain assemblies with the same name. AFAIK people should move to the newer “System.Net.Http” package but I’m afraid that’s not always under our control. Some 3rd party libraries might still use “Microsoft.Net.Http” and others might already use “System.Net.Http”.
Steps to reproduce
These are two sample projects that fail:
{
"version": "1.0.0-*",
"compilationOptions": {
"warningsAsErrors": true
},
"dependencies": {
"Microsoft.Bcl.Immutable": "1.0.34",
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final"
},
"frameworks": {
"net46": { }
}
}
Error: An item with the same key has already been added. Key: (System.Collections.Immutable, neutral, b03f5f7f11d50a3a)
{
"version": "1.0.0-*",
"compilationOptions": {
"warningsAsErrors": true
},
"dependencies": {
"Hyak.Common": "1.1.0",
"System.Net.Http.Formatting.Extension": "5.2.3"
},
"frameworks": {
"net46": { }
}
}
Error: An item with the same key has already been added. Key: (System.Net.Http.Extensions, neutral, b03f5f7f11d50a3a)
Expected behavior
I’m not sure if these are exactly the same libraries and a binding redirect would solve the problem. I’ve seen that there are already some other issues (eg dotnet/sdk#4805 ) on that topic.
If it can’t be solved with a binding redirect, maybe it can be resolved by renaming the libraries?
If this can’t be fixed, how should we proceed in such cases? If the vendor of the library doesn’t change his dependencies we might end up in a blocking situation.
Environment data
dotnet --version
output:
.NET Command Line Tools (1.0.0-beta-001718)
Product Information:
Version: 1.0.0-beta-001718
Commit Sha: 5b0afe7880
Runtime Environment:
OS Name: Windows
OS Version: 10.0.10586
OS Platform: Windows
Runtime Id: win10-x86
Issue Analytics
- State:
- Created 8 years ago
- Reactions:2
- Comments:27 (3 by maintainers)
I found another solution that seems to fix this problem, do a:
I start hitting this on VS Update 3.
How to repro:
Actual: Error An item with the same key has already been added. Key: Microsoft.Azure.Test.HttpRecorder TestFramework C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets 241
Expected: Build successful.