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 Build Error: An item with the same key has already been added.

See original GitHub issue

Issue moved from microsoft/msbuild#5509


From @rlmartins76 on Sunday, July 12, 2020 9:06:17 PM

C:\Program Files\dotnet\sdk\3.1.301\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(194,5): error MSB4018: The "GenerateDepsFile" task failed unexpectedly.
C:\Program Files\dotnet\sdk\3.1.301\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(194,5): error MSB4018: System.ArgumentException: An item with the same key has already been added.
C:\Program Files\dotnet\sdk\3.1.301\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(194,5): error MSB4018:    at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
C:\Program Files\dotnet\sdk\3.1.301\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(194,5): error MSB4018:    at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
C:\Program Files\dotnet\sdk\3.1.301\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(194,5): error MSB4018:    at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
C:\Program Files\dotnet\sdk\3.1.301\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(194,5): error MSB4018:    at Microsoft.Extensions.DependencyModel.DependencyContextWriter.WritePortableTarget(IReadOnlyList`1 runtimeLibraries, IReadOnlyList`1 compilationLibraries)
C:\Program Files\dotnet\sdk\3.1.301\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(194,5): error MSB4018:    at Microsoft.Extensions.DependencyModel.DependencyContextWriter.WriteTargets(DependencyContext context)
C:\Program Files\dotnet\sdk\3.1.301\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(194,5): error MSB4018:    at Microsoft.Extensions.DependencyModel.DependencyContextWriter.Write(DependencyContext context)
C:\Program Files\dotnet\sdk\3.1.301\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(194,5): error MSB4018:    at Microsoft.Extensions.DependencyModel.DependencyContextWriter.Write(DependencyContext context, Stream stream)
C:\Program Files\dotnet\sdk\3.1.301\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(194,5): error MSB4018:    at Microsoft.NET.Build.Tasks.GenerateDepsFile.WriteDepsFile(String depsFilePath)
C:\Program Files\dotnet\sdk\3.1.301\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(194,5): error MSB4018:    at Microsoft.NET.Build.Tasks.GenerateDepsFile.ExecuteCore()
C:\Program Files\dotnet\sdk\3.1.301\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(194,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute()
C:\Program Files\dotnet\sdk\3.1.301\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(194,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
C:\Program Files\dotnet\sdk\3.1.301\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(194,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:5

github_iconTop GitHub Comments

1reaction
mikegoatlycommented, Aug 5, 2020

Figured my problem out - I’d changed the PackageId of a project to a name that matched the name of another project that referenced it. To be honest I didn’t expect the PackageId to have any effect when using a project reference, but you live and learn.

0reactions
jeanplevesquecommented, Jan 13, 2023

Figured my problem out - I’d changed the PackageId of a project to a name that matched the name of another project that referenced it. To be honest I didn’t expect the PackageId to have any effect when using a project reference, but you live and learn.

I’ve had the same problem, but in my case I had 2 projects with the same AssemblyName (and different values for PackageId).

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
compilation error MSB4018: The “GenerateDepsFile” task ...
Error MSB4018 The “GenerateDepsFile” task failed unexpectedly. 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 ...
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 >
GenerateDepsFile task failed unexpectedly
All of a sudden, building with Travis is failing. travis.yml hasn't been modified between then and now. The error message is as follows:....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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