question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GenerateDepsFile task failing with "System.ArgumentException: An item with the same key has already been added."

See original GitHub issue

Steps to reproduce

Sorry, wasn’t able to make a nice little minimal repro for this one. In PowerShell:

  1. git clone https://github.com/joelverhagen/NuGet.Client.git
  2. cd NuGet.Client
  3. git checkout jver/sdk-repro
  4. cd src\NuGet.Core
  5. Get-ChildItem .\*.csproj -Recurse | % { dotnet restore3 $_.FullName }
  6. 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:closed
  • Created 7 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
eerhardtcommented, Oct 14, 2016

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.

0reactions
joelverhagencommented, Oct 18, 2016

Confirmed with Microsoft.NET.Sdk/1.0.0-alpha-20161018-2.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found