Skip to content

[CPVM-OnBoard] Rejected transitive central dependencies should be removed from the restore graph. #9483

Closed

Description

@cristinamanum

Details about Problem

The Restore of projects opted-in CPVM fails with 'System.Collections.Generic.KeyNotFoundException" if a central dependency is part of a sub graph that was rejected.
Using the attached example, the exception happens because the central dependency "System.IO.Compression.ZipFile" is added to the graph as dependency on NETStandard.Library >= 1.6.1.

However the NETStandard.Library >= 1.6.1 is rejected in the favor of NETStandard.Library >= 2.0.3 but the centrally marked dependency is not.

The issue manifests as an exception:
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary2.get_Item(TKey key) at NuGet.Commands.LockFileBuilder.<>c__DisplayClass8_1.<AddCentralTransitiveDependencyGroupsForPackageReference>b__3(GraphItem1 graphItem)
at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() at System.Linq.Enumerable.Any[TSource](IEnumerable1 source)
at NuGet.Commands.LockFileBuilder.AddCentralTransitiveDependencyGroupsForPackageReference(PackageSpec project, LockFile lockFile, IEnumerable1 targetGraphs) at NuGet.Commands.LockFileBuilder.CreateLockFile(LockFile previousLockFile, PackageSpec project, IEnumerable1 targetGraphs, IReadOnlyList1 localRepositories, RemoteWalkContext context) at NuGet.Commands.RestoreCommand.BuildAssetsFile(LockFile existingLockFile, PackageSpec project, IEnumerable1 graphs, IReadOnlyList`1 localRepositories, RemoteWalkContext contextForProject)
at NuGet.Commands.RestoreCommand.d__33.MoveNext()
--- End of stack trace from previous location where exception was thrown ---

Detailed repro steps so we can see the same problem

  1. Download the attached file

  2. msbuild /t:restore /v:d on the attached project.

Sample Project

RejectedCentralTransitiveDep.zip

Note

Projects in the NuGet Client repo that manifests this issue:
NuGet.Core.Tests\NuGet.LibraryModel.Tests
NuGet.Core.Tests\NuGet.Shared.Tests
NuGet.Core.Tests\NuGet.Versioning.Test
NuGet.Core.Tests\NuGet.Resolver.Test

Activity

  1. changed the title [-]Rejected transitive central dependencies should be removed from the restore graph.[/-] [+][CPVM-OnBoard]Rejected transitive central dependencies should be removed from the restore graph.[/+] on May 21, 2020
  2. changed the title [-][CPVM-OnBoard]Rejected transitive central dependencies should be removed from the restore graph.[/-] [+][CPVM-OnBoard] Rejected transitive central dependencies should be removed from the restore graph.[/+] on May 21, 2020
  3. rconard commented on Aug 27, 2020

    @rconard

    Updates to CPVM will only be included in the .NET 5 SDK. You can target .NET Core and .NET Framework from the .NET 5 SDK.

    .NET Core runtimes and SDK's are decoupled, but they share the same major and minor versions. Any version of the .NET Core or .NET 5 SDK can build any .NET Framework app or any .NET Core app that is equal to or lower than the version of the SDK installed if the relevant Targeting Pack is installed.

    Currently, installing the .NET 5 SDK requires installing the preview version of Visual Studio. In the future when .NET 5 is released, it will be possible to install the .NET 5 SDK in the General Availability channel of Visual Studio.

  4. lippinio commented on Aug 28, 2020

    @lippinio

    We tried the CPVM yesterday and we think it's a great feature. Today we have updated from dotnet sdk 3.1.100 to 3.1.401.
    And we get the System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. in the restore. With the attached zip we could exactly reproduce the failure.
    As I understand a pontential fix will only be included in the .NET 5 sdk is this correct?

    >C:\Program Files\dotnet\sdk\3.1.401\NuGet.targets(128,5): error : The given key 'System.IO.Compression.ZipFile' was not present in the dictionary. System.Collections.Generic.KeyNotFoundException: The given key 'System.IO.Compression.ZipFile' was not present in the dictionary. at System.Collections.Generic.Dictionary2.get_Item(TKey key)
    at NuGet.Commands.LockFileBuilder.<>c__DisplayClass8_1.b__3(GraphItem1 graphItem) at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()
    at System.Linq.Enumerable.Any[TSource](IEnumerable1 source) at NuGet.Commands.LockFileBuilder.AddCentralTransitiveDependencyGroupsForPackageReference(PackageSpec project, LockFile lockFile, IEnumerable1 targetGraphs)
    at NuGet.Commands.LockFileBuilder.CreateLockFile(LockFile previousLockFile, PackageSpec project, IEnumerable1 targetGraphs, IReadOnlyList1 localRepositories, RemoteWalkContext context)
    at NuGet.Commands.RestoreCommand.ExecuteAsync(CancellationToken token)
    at NuGet.Commands.RestoreRunner.ExecuteAsync(RestoreSummaryRequest summaryRequest, CancellationToken token)
    at NuGet.Commands.RestoreRunner.ExecuteAndCommitAsync(RestoreSummaryRequest summaryRequest, CancellationToken token)
    at NuGet.Commands.RestoreRunner.CompleteTaskAsync(List1 restoreTasks) at NuGet.Commands.RestoreRunner.RunAsync(IEnumerable1 restoreRequests, RestoreArgs restoreContext, CancellationToken token)
    at NuGet.Commands.RestoreRunner.RunAsync(RestoreArgs restoreContext, CancellationToken token)
    at NuGet.Build.Tasks.BuildTasksUtility.RestoreAsync(DependencyGraphSpec dependencyGraphSpec, Boolean interactive, Boolean recursive, Boolean noCache, Boolean ignoreFailedSources, Boolean disableParallel, Boolean force, Boolean forceEvaluate, Boolean hideWarningsAndErrors, Boolean restorePC, Boolean cleanupAssetsForUnsupportedProjects, ILogger log, CancellationToken cancellationToken)
    at NuGet.Build.Tasks.RestoreTask.ExecuteAsync(ILogger log)`
    @rconard @zivkan

  5. rconard commented on Aug 31, 2020

    @rconard

    @lippinio
    Fixes are included in the .NET 5 SDK, but you can use this build SDK to target .NET Core 3.1.401.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions