skip to Main Content

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


  1. Chosen as BEST ANSWER

    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.


  2. My problem was with Nuget Package which was not exist

    <PackageReference Include="System.Collections.Immutable" Version="1.2.5.0" />
    

    Solution

    <PackageReference Include="System.Collections.Immutable" Version="7.0.0" />
    
    Login or Signup to reply.
  3. In my case, the deeper error looked something like this:

    Could not find SDK "Microsoft.UniversalCRT.Debug, Version=10.0.18362.0"
    

    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) in Visual Studio -> Tools -> Get Tools and Features....

    See this response to an issue on the WinUI Gallery.

    Login or Signup to reply.
  4. I ran into the same error for unrelated reasons.
    Running:

    dotnet restore
    

    from CLI in the solution root directory gave me some better info on what was actually going on.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search