{"record":{"id":"7f894fc2d05ad589","repo":"stride3d/stride","slug":"could-not-restore-nuget-packages-for-packagename","errorCode":null,"errorMessage":"Could not restore NuGet packages for {packageName} {packageVersion} ({targetFramework}).{Environment.NewLine}{diagnostics}","messagePattern":"Could not restore NuGet packages for (.+?) (.+?) \\((.+?)\\)\\.(.+?)(.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/shared/Stride.NuGetResolver/NuGetAssemblyResolver.cs","lineNumber":138,"sourceCode":"                    {\n                        // Since we execute restore synchronously, we don't want any surprise concerning synchronization context (i.e. Avalonia one doesn't work with this)\n                        SynchronizationContext.SetSynchronizationContext(null);\n\n                        foreach (var (targetFramework, packageName, packageVersion) in packagesConfigs)\n                        {\n                            // Parse current TFM\n                            var nugetFramework = NuGetFramework.Parse(targetFramework);\n\n                            // Only allow this specific version\n                            var versionRange = new VersionRange(new NuGetVersion(packageVersion), true, new NuGetVersion(packageVersion), true);\n                            var (request, result) = RestoreHelper.Restore(logger, nugetFramework, RuntimeInformation.RuntimeIdentifier, packageName, versionRange);\n                            if (!result.Success)\n                            {\n                                var diagnostics = string.Join(Environment.NewLine,\n                                    logger.Logs\n                                        .Where(l => l.Level >= LogLevel.Warning)\n                                        .Select(l => $\"  [{l.Level}] {l.Message}\"));\n                                throw new InvalidOperationException(\n                                    $\"Could not restore NuGet packages for {packageName} {packageVersion} ({targetFramework}).{Environment.NewLine}{diagnostics}\");\n                            }\n\n                            // Deployed path: pick the selected API's subfolder per package (null -> platform default).\n                            var assemblies = RestoreHelper.ListAssemblies(result.LockFile, selectedGraphicsApi);\n\n                            // Create a dictionary by assembly name\n                            // note: we ignore case as filename might not be properly matching assembly name casing\n                            assemblyNameToPath ??= new(StringComparer.OrdinalIgnoreCase);\n                            foreach (var assembly in assemblies)\n                            {\n                                var extension = Path.GetExtension(assembly).ToLowerInvariant();\n                                if (extension != \".dll\")\n                                    continue;\n                                var assemblyName = Path.GetFileNameWithoutExtension(assembly);\n                                // Ignore duplicates (however, make sure it's the same version otherwise display a warning)\n                                if (assemblyNameToPath.TryGetValue(assemblyName, out var otherAssembly))\n                                {","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shared/Stride.NuGetResolver/NuGetAssemblyResolver.cs#L120-L156","documentation":"NuGetAssemblyResolver.SetupNuGet restores the Stride runtime NuGet packages and then collects all log entries at Warning level or above into 'diagnostics'. If the restore result reports Success == false, it throws an InvalidOperationException embedding the package name, version, target framework and those diagnostics. The real cause is always inside the appended diagnostics text.","triggerScenarios":"Calling SetupNuGet when the NuGet restore of packageName/packageVersion for targetFramework fails: unreachable feed, 404 for that package/version, authentication failure on a private feed, or inconsistent dependency graph.","commonSituations":"Wrong or nonexistent Stride package version pinned; offline machine or corporate proxy blocking nuget.org; missing NuGet.config / private feed credentials; target framework not supported by the package.","solutions":["Read the diagnostics appended to the message — it names the exact restore failure (404, auth, conflict).","Verify the package id and version exist on the configured feed (dotnet package search / nuget.org).","Check NuGet.config feeds, credentials, and network/proxy access; run 'dotnet restore' manually to reproduce.","Ensure the requested targetFramework matches a TFM the package supports."],"exampleFix":"// before (no feed configured)\nSetupNuGet(\"Stride.Core\", \"9.9.9\", \"net8.0\");\n// after: use a published version and restore offline cache\n// nuget.config: <packageSources><add key=\"nuget.org\" value=\"https://api.nuget.org/v3/index.json\" /></packageSources>\nSetupNuGet(\"Stride.Core\", \"4.2.1\", \"net8.0\");","handlingStrategy":"try-catch","validationCode":"// Pre-check package availability before SetupNuGet\nusing var http = new HttpClient();\nvar url = $\"https://api.nuget.org/v3-flatcontainer/{packageName.ToLowerInvariant()}/{packageVersion}/{packageName.ToLowerInvariant()}.nuspec\";\nif (!http.SendAsync(new HttpRequestMessage(HttpMethod.Head, url)).Result.IsSuccessStatusCode)\n    throw new InvalidOperationException($\"Package {packageName} {packageVersion} not available on the feed.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    resolver.SetupNuGet(packageName, packageVersion, targetFramework);\n}\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Could not restore NuGet packages\"))\n{\n    // diagnostics are embedded in ex.Message — log them verbatim for triage\n    logger.Error(ex.Message);\n    throw;\n}","preventionTips":["Pin Stride package versions that actually exist on the feed.","Commit a NuGet.config with the correct sources and credentials for CI.","Warm the NuGet cache (dotnet restore) before running the resolver in offline/sandboxed environments."],"tags":["nuget","restore","package-resolution"],"backgroundTag":"api-request-failed","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}