dotnet/reactive · error · InvalidOperationException

Unexpected failure when building NuGet package to be consume

Error message

Unexpected failure when building NuGet package to be consumed by test app

What it means

RunTransitiveFrameworkReferenceCheck.RunScenarioAsync builds a local NuGet package that a test app will consume; if dotnet pack reports BuildSucceeded == false it throws InvalidOperationException('Unexpected failure when building NuGet package to be consumed by test app'). The library treats a failed pack as a scenario failure because the transitive-reference check cannot proceed without the package.

Solutions

  1. Inspect the pack build log (packageBuildResult output) for the real compiler/pack error and fix it
  2. Verify additionalPackageSources contains all feeds needed to restore dependencies
  3. Run dotnet pack on the project manually to reproduce the failure
  4. Clear bin/obj and retry to rule out stale build state
Defensive patterns

Strategy: try-catch

Validate before calling

var pack = dotnet pack -c Release <libProject> -o <out>;
if (pack.ExitCode != 0 || !Directory.GetFiles(out, "*.nupkg").Any())
    throw new InvalidOperationException("Pack will fail; fix errors before running the check");

Try / catch

try
{
    await check.RunScenarioAsync(...);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("building NuGet package"))
{
    // inspect pack log, fix compile/pack error, re-run
}

Prevention

When it happens

Trigger: The inner NuGet pack step (run with additionalPackageSources) returns a result whose BuildSucceeded is false — a compile error or pack failure in the library project being packaged.

Common situations: C# compile error in the source being packed; missing NuGet feed in additionalPackageSources; pack target failing due to invalid package metadata (ids, versions); stale obj/bin state.

Related errors


AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15). Data as JSON: /api/errors/4633a9d91d0398af. Report an issue: GitHub.

Appendix: source

Thrown at Rx.NET/Test/Gauntlet/Checks/TransitiveReferences/CheckTransitiveFrameworkReference/RunTransitiveFrameworkReferenceCheck.cs:134

                            // to a legacy facade, but a component has a reference to System.Reactive v7. I don't think
                            // that's a thing a library should ever do but perhaps we need to test it.

                            var replaceSystemReactiveWith = ld.HasWindowsTargetUsingUiFrameworkSpecificRxFeature
                                ? [.. newRxMainAndIfRequiredLegacyPackage, .. rxUiPackages]
                                : newRxMainAndIfRequiredLegacyPackage;
                            project.ReplacePackageReference("System.Reactive", replaceSystemReactiveWith);
                        }

                        if (!ld.HasWindowsTargetUsingUiFrameworkSpecificRxFeature)
                        {
                            project.ReplaceProperty("_ScenarioWindowsDefineConstants", "");
                        }
                    },
                    additionalPackageSources);

                if (!packageBuildResult.BuildSucceeded)
                {
                    throw new InvalidOperationException("Unexpected failure when building NuGet package to be consumed by test app");
                }

                _builtLibPackages.Add(ld, new PackageIdAndVersion(assemblyName, packageVersion));
            }
        }

        RxDependency[] libs =
            [
                ..scenario.RxDependenciesBefore,
                ..scenario.RxDependenciesAfter,
            ];
        foreach (var dependency in libs)
        {
            await dependency.Match(
                (DirectRxPackageReference _) => Task.CompletedTask,
                ProcessLib);
        }

View on GitHub (pinned to 94b5d5ab91)