stride3d/stride · error · InvalidOperationException

Could not restore package

Error message

Could not restore package {packageId}

What it means

Thrown by NugetStore.InstallPackage after running a NuGet restore command whose result.Success is false — the runtime restore of a package failed and no install graph could be read. The library surfaces the raw failure as an InvalidOperationException keyed by packageId because NuGet's restore result does not itself throw.

Solutions

  1. Verify the package id and exact version exist on the configured sources (nuget.org or custom feed) and correct the arguments
  2. Run the restore manually (dotnet restore / nuget restore against the same source) to see the underlying NuGet error message
  3. Check network/proxy and feed credentials; add the feed via nuget.config or NugetStore source configuration and retry
  4. Clear the NuGet cache (dotnet nuget locals http-cache --clear) and retry; wrap InstallPackage in try/catch to report packageId

Example fix

// before
var package = await store.InstallPackage(null, LogProgress, new PackageName("MyGame.Plugin", "1.0.0"));
// after
try
{
    var package = await store.InstallPackage(null, LogProgress, new PackageName("MyGame.Plugin", "1.0.0"));
}
catch (InvalidOperationException ex)
{
    Log.Error($"Restore failed for {ex.Message}; check feed URL, credentials and version.");
}
Defensive patterns

Strategy: retry

Validate before calling

var exists = await store.FindSourcePackage(new NugetVersion(packageName.Version, packageName.Version)); // confirm id/version exists before installing
if (exists == null) throw new ArgumentException($"Package {packageName} not found in configured sources");

Type guard

bool IsRestoreFailure(InvalidOperationException ex) => ex.Message.StartsWith("Could not restore package");

Try / catch

try { return await store.InstallPackage(null, progress, packageName); } catch (InvalidOperationException ex) { log.Error($"Restore of {packageName} failed: {ex.Message}"); throw; }

Prevention

When it happens

Trigger: Calling NugetStore.InstallPackage (directly or via installedPackage) when NuGet's RestoreCommand.ExecuteAsync returns a result with Success == false — e.g. the package/version does not exist in the configured sources, the feed is unreachable, or auth fails.

Common situations: Offline or misconfigured NuGet feed (wrong source URL, expired credentials); requesting a package version that was unlisted/deleted; corporate proxy blocking nuget.org; corrupted NuGet http-cache.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/1e877cb4198086ef. Report an issue: GitHub.

Appendix: source

Thrown at sources/assets/Stride.Core.Packages/NugetStore.cs:606

                        foreach (var request in requests)
                        {
                            // Limit concurrency to avoid timeout
                            request.Request.MaxDegreeOfConcurrency = 4;
                            request.Request.DependencyProviders = providersCache.GetOrCreate(
                                installPath,
                                spec.RestoreMetadata.FallbackFolders.ToList(),
                                progressSources,
                                context,
                                NativeLogger);

                            var command = new RestoreCommand(request.Request);

                            // Act
                            var result = await command.ExecuteAsync();

                            if (!result.Success)
                            {
                                throw new InvalidOperationException($"Could not restore package {packageId}");
                            }
                            var toInstall = result.RestoreGraphs.Last().Install;
                            NugetRestoreInstalling?.Invoke(toInstall.Count);
                            foreach (var install in toInstall)
                            {
                                var package = result.LockFile.Libraries.FirstOrDefault(x => x.Name == install.Library.Name && x.Version == install.Library.Version);
                                if (package != null)
                                {
                                    var packagePath = Path.Combine(installPath, package.Path);
                                    OnPackageInstalled(this, new PackageOperationEventArgs(new PackageName(install.Library.Name, install.Library.Version.ToPackageVersion()), packagePath));
                                }
                            }
                        }
                    }

                    if (packageId == "Xenko" && version < new PackageVersion(3, 0, 0, 0))
                    {
                        UpdateTargetsHelper();

View on GitHub (pinned to 96fad776d2)