Skip to content

New dependency resolver silently accepts package dependency cycles when incoming version ranges differ (missing NU1108) #15150

Open

Description

@trackoor

NuGet Product Used

dotnet.exe, MSBuild.exe

Product Version

.NET SDK 11.0.100 (NuGet 8.0.0-rc.53118+297acf930f), .NET SDK 10.0.404 (NuGet 7.9.0-rc.3019+2ab2854867), NuGet/NuGet.Client dev 1e37797354 (8.2.0-rc.65534)

Worked before?

Yes, in .NET SDK 8.0.x (prior to NuGet 6.12 enabling the new dependency resolver by default) and when setting RestoreUseLegacyDependencyResolver=true.

Impact

It's more difficult to complete my work

Repro Steps & Context

When a circular package dependency enters the revisited package with a different VersionRange than the ancestor edge (for example App -> LibA 2.0.0 -> LibB 1.0.0 -> LibA 1.0.0, or LibA 1.0.0 -> LibB 1.0.0 -> LibA [1.0.0]), the default dependency resolver succeeds without reporting NU1108 and writes the cycle into project.assets.json.

Save as repro.sh and run sh repro.sh in an empty directory (set TFM=net11.0 if testing on a standalone .NET 11 SDK):

#!/bin/sh
set -eu
DOTNET=${DOTNET:-dotnet}
TFM=${TFM:-net10.0}
export DOTNET_CLI_TELEMETRY_OPTOUT=1
FEED="$PWD/feed"
CACHE="$PWD/packages"
mkdir -p "$FEED" liba libb app

cat > liba/LibA.csproj <<XML
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>${TFM}</TargetFramework>
    <NoPackageAnalysis>true</NoPackageAnalysis>
  </PropertyGroup>
</Project>
XML

cat > liba/LibA.nuspec <<XML
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata>
    <id>LibA</id>
    <version>2.0.0</version>
    <authors>test</authors>
    <description>test</description>
    <dependencies>
      <group targetFramework="${TFM}">
        <dependency id="LibB" version="1.0.0" />
      </group>
    </dependencies>
  </metadata>
</package>
XML

cat > libb/LibB.csproj <<XML
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>${TFM}</TargetFramework>
    <NoPackageAnalysis>true</NoPackageAnalysis>
  </PropertyGroup>
</Project>
XML

cat > libb/LibB.nuspec <<XML
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata>
    <id>LibB</id>
    <version>1.0.0</version>
    <authors>test</authors>
    <description>test</description>
    <dependencies>
      <group targetFramework="${TFM}">
        <dependency id="LibA" version="1.0.0" />
      </group>
    </dependencies>
  </metadata>
</package>
XML

"$DOTNET" pack liba/LibA.csproj -p:NuspecFile=LibA.nuspec -o "$FEED" --nologo -v q
"$DOTNET" pack libb/LibB.csproj -p:NuspecFile=LibB.nuspec -o "$FEED" --nologo -v q

cat > app/NuGet.Config <<XML
<configuration>
  <packageSources>
    <clear />
    <add key="local" value="$FEED" />
  </packageSources>
</configuration>
XML

cat > app/App.csproj <<XML
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>${TFM}</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="LibA" Version="2.0.0" />
  </ItemGroup>
</Project>
XML

echo "=== Default dependency resolver ==="
"$DOTNET" restore app/App.csproj --configfile app/NuGet.Config --packages "$CACHE" --force --no-cache --nologo
echo "exit=$?"

echo "=== dotnet nuget why ==="
"$DOTNET" nuget why app/App.csproj OtherPkg 2>&1 | head -n 6 || true

echo "=== Legacy dependency resolver ==="
"$DOTNET" restore app/App.csproj --configfile app/NuGet.Config --packages "$CACHE" --force --no-cache --nologo -p:RestoreUseLegacyDependencyResolver=true || echo "exit=$?"

What I got:

=== Default dependency resolver ===
  Determining projects to restore...
  Restored /tmp/repro/app/App.csproj (in 218 ms).
exit=0
=== dotnet nuget why ===
Stack overflow.
   at System.Collections.Generic.List`1[[System.__Canon, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].System.Collections.Generic.IEnumerable<T>.GetEnumerator()
   at NuGet.CommandLine.XPlat.Commands.Why.DependencyGraphFinder.CreateNode(NuGet.ProjectModel.LockFileTarget, System.String, NuGet.ProjectModel.LockFileTargetLibrary, NuGet.Versioning.VersionRange)
   at NuGet.CommandLine.XPlat.Commands.Why.DependencyGraphFinder.CreateNode(NuGet.ProjectModel.LockFileTarget, System.String, NuGet.ProjectModel.LockFileTargetLibrary, NuGet.Versioning.VersionRange)
   at NuGet.CommandLine.XPlat.Commands.Why.DependencyGraphFinder.CreateNode(NuGet.ProjectModel.LockFileTarget, System.String, NuGet.ProjectModel.LockFileTargetLibrary, NuGet.Versioning.VersionRange)
   at NuGet.CommandLine.XPlat.Commands.Why.DependencyGraphFinder.CreateNode(NuGet.ProjectModel.LockFileTarget, System.String, NuGet.ProjectModel.LockFileTargetLibrary, NuGet.Versioning.VersionRange)
=== Legacy dependency resolver ===
  Determining projects to restore...
/tmp/repro/app/App.csproj : error NU1108: Cycle detected. 
/tmp/repro/app/App.csproj : error NU1108:   App -> LibA 2.0.0 -> LibB 1.0.0 -> LibA (>= 1.0.0).
  Failed to restore /tmp/repro/app/App.csproj (in 165 ms).
exit=1

In app/obj/project.assets.json, targets contains the cycle LibA/2.0.0 -> LibB 1.0.0 and LibB/1.0.0 -> LibA 1.0.0, which causes dotnet nuget why (DependencyGraphFinder.CreateNode, which assumes project.assets.json has no circular dependencies) to stack-overflow when searching for any package outside the cycle.

What I expected:

Both dependency resolvers reject the circular dependency graph with error NU1108: Cycle detected (https://learn.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu1108) and exit with a non-zero status code.

Likely cause: in DependencyGraphResolver.CreateRestoreTargetGraphAsync (src/NuGet.Core/NuGet.Commands/RestoreCommand/DependencyGraphResolver.cs), revisiting an already-seen childLibraryDependencyIndex checks resolvedDependencyGraphItem.Path.Contains(currentRangeIndex) using LibraryRangeIndex (keyed on package ID and VersionRange) rather than LibraryDependencyIndex (package ID), so any cycle whose back-edge specifies a distinct VersionRange bypasses the cycle check.

Verbose Logs

No response

Credit: https://ucsbplse.github.io/

Activity

  1. dotnet-policy-service commented on Nov 17, 2026

    @dotnet-policy-service
    Contributor

    Issue is missing Type label, remember to add a Type label

  2. added
    missing-required-type
    on Nov 17, 2026
  3. added
    Area:NewDependencyResolver
    on Nov 17, 2026
  4. jebriede commented on Nov 17, 2026

    @jebriede
    Contributor

    I was able to reproduce this with SDK 10.0.404. The default resolver succeeds and writes the package cycle to project.assets.json; the legacy resolver rejects it with NU1108.

  5. removed
    missing-required-type
    on Nov 17, 2026
  6. added
    Priority:2
    on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area:NewDependencyResolverFunctionality:RestorePriority:2Type:Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions