GenerateDepsFile task failing with "System.ArgumentException: An item with the same key has already been added."
See original GitHub issueSteps to reproduce
Sorry, wasn’t able to make a nice little minimal repro for this one. In PowerShell:
git clone https://github.com/joelverhagen/NuGet.Client.git
cd NuGet.Client
git checkout jver/sdk-repro
cd src\NuGet.Core
Get-ChildItem .\*.csproj -Recurse | % { dotnet restore3 $_.FullName }
dotnet build3 NuGet.RuntimeModel\NuGet.RuntimeModel.csproj
Expected behavior
The build should succeed… or at least no fail with this error 😄. I’ve been working through a lot of failures so it’s possible there’s another waiting in line.
Actual behavior
Build fails.
The "GenerateDepsFile" task failed unexpectedly.
System.ArgumentException: An item with the same key has already been added. Key: Newtonsoft.Json
at System.ThrowHelper.ThrowAddingDuplicateWithKeyArgumentException(Object key)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Linq.Enumerable.ToDictionary
at System.Linq.Enumerable.ToDictionary
at Microsoft.NET.Build.Tasks.DependencyContextBuilder.Build(SingleProjectInfo mainProjectInfo, CompilationOptions compilationOptions, LockFile lockFile, NuGetFramework framework, String runtime)
at Microsoft.NET.Build.Tasks.GenerateDepsFile.ExecuteCore()
at Microsoft.NET.Build.Tasks.TaskBase.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__25.MoveNext()
Environment data
dotnet --info
output:
.NET Command Line Tools (1.0.0-preview3-003842)
Product Information:
Version: 1.0.0-preview3-003842
Commit SHA-1 hash: 3ae14ab618
Runtime Environment:
OS Name: Windows
OS Version: 10.0.14393
OS Platform: Windows
RID: win10-x64
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
GenerateDepsFile Build Error: An item with the same key ...
NET.Sdk\targets\Microsoft.NET.Sdk.targets(194,5): error MSB4018: System.ArgumentException: An item with the same key has already been added.
Read more >NET Core solution build gives a GenerateDepsFile error
It tries to add an item to a dictionary when it already exists, but not which dictionary it is trying or what duplicate...
Read more >error MSB4018: The “GenerateDepsFile” task failed ...
Sdk.targets(194,5): error MSB4018: System.ArgumentException: An item with the same key has already been added.
Read more >The "GenerateDepsFile" task failed unexpectedly. I ...
I Created the new console application (.NET 6) , even that is showing the same error. 0 votes
Read more >Error MSB4018: the “generatedepsfile” task failed ...
Sdk.targets(194,5): error MSB4018: System.ArgumentException: An item with the same key has already been added.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Looks like I had a bad assumption when I wrote this code. 😞 Looking at the CLI code, it uses https://github.com/dotnet/cli/blob/rel/1.0.0/src/Microsoft.DotNet.ProjectModel/Graph/LockFileLookup.cs.
I’ll do the same in the sdk code - with one addition: it will handle case-insensitive package IDs.
Confirmed with
Microsoft.NET.Sdk/1.0.0-alpha-20161018-2
.