I have a .net5 project and I need to debug a library used by this project. To do so, I have unistalled the NuGet package of my library and add the project reference to my project.
Now, I can not build the project.
After the build I get the following errors:
The "ResolvePackageDependencies" task failed unexpectedly.
System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.GetPackageAndFileDependencies(LockFileTarget target)
at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.RaiseLockFileTargets()
at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.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__26.MoveNext() Project.Namespace C:Program Filesdotnetsdk6.0.202SdksMicrosoft.NET.Sdktargets C:Program Filesdotnetsdk6.0.202SdksMicrosoft.NET.SdktargetsMicrosoft.PackageDependencyResolution.targets
And
The "ResolvePackageAssets" task failed unexpectedly
System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
at Microsoft.NET.Build.Tasks.ProjectContext.GetTopLevelDependencies(LockFile lockFile, LockFileTarget lockFileTarget)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.ComputePackageExclusions()
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter..ctor(ResolvePackageAssets task)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader.CreateReaderFromDisk(ResolvePackageAssets task, Byte[] settingsHash)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader..ctor(ResolvePackageAssets task)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups()
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.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__26.MoveNext() Project.Namespace C:Program Filesdotnetsdk6.0.202SdksMicrosoft.NET.Sdktargets C:Program Filesdotnetsdk6.0.202SdksMicrosoft.NET.SdktargetsMicrosoft.PackageDependencyResolution.targets
There are no duplicates packages in the csproj.
How can I solve this?
I have already tried to:
- Delete bin, obj and .vs folder
- Restore Nuget packages
- Clear all NuGet cache
Thanks.
4
Answers
I found the solution. The problem was that another Solution project still referenced the NuGet package and not the local project. So it was enough to remove the dependency and add the reference to the local package.
My problem was with Nuget Package which was not exist
Solution
In my case, the deeper error looked something like this:
This was because I didn’t have the correct Windows SDK installed. In my case, I had to install
Windows 10 SDK (10.0.18362.0)
inVisual Studio -> Tools -> Get Tools and Features...
.See this response to an issue on the WinUI Gallery.
I ran into the same error for unrelated reasons.
Running:
from CLI in the solution root directory gave me some better info on what was actually going on.