{"record":{"id":"e9dea08b9a64f579","repo":"dotnet/maui","slug":"failed-to-download-the-package","errorCode":null,"errorMessage":"Failed to download the package.","messagePattern":"Failed to download the package\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"eng/cake/helpers.cake","lineNumber":148,"sourceCode":"    var packageVersion = NuGetVersion.Parse(version);\n    var cacheContext = new SourceCacheContext();\n    \n    // Set up logging (optional, use NullLogger if you don't need logging)\n    ILogger logger = NullLogger.Instance;\n\n    // Download the package to the output directory\n    EnsureDirectoryExists(outputDirectory);\n    var packagePath = System.IO.Path.Combine(outputDirectory, $\"{packageId}.{version}.nupkg\");\n    \n    using (var fileStream = new FileStream(packagePath, FileMode.Create, FileAccess.Write, FileShare.None))\n    {\n        // Download package\n        var success = await resource.CopyNupkgToStreamAsync(\n            packageId, packageVersion, fileStream, cacheContext, logger, default);\n\n        if (!success)\n        {\n            throw new Exception(\"Failed to download the package.\");\n        }\n\n        Information(\"Package '{0} v{1}' downloaded successfully to {2}\", packageId, version, packagePath);\n    }\n}\n","sourceCodeStart":130,"sourceCodeEnd":154,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/eng/cake/helpers.cake#L130-L154","documentation":"Thrown by the NuGet package download helper when CopyNupkgToStreamAsync returns false, meaning the server/protocol could not fulfill the download for the requested packageId/version. The file stream has already been created (possibly empty/partial) at packagePath, but the download is treated as failed and aborted before reporting success.","triggerScenarios":"resource.CopyNupkgToStreamAsync(packageId, packageVersion, fileStream, cacheContext, logger, default) returns false for the requested packageId and version against the configured NuGet source.","commonSituations":"The package id/version does not exist on the configured feed; the feed URL/auth is wrong or the PAT has expired; a transient network failure or HTTP 429; a typo in the version string; the local HTTP cache is corrupt.","solutions":["Verify the packageId and version exist on the feed: `dotnet nuget list <packageId>` or browse the feed UI.","Check NuGet.config source URLs and credentials/PAT validity used by the script.","Clear the local NuGet HTTP cache (`dotnet nuget locals http-cache --clear`) and retry in case of a corrupt cached response.","For transient errors, retry the cake target; if it persists, capture verbose logger output to see the underlying NuGet error."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Validate package existence on the feed before downloading\nvar found = await resource.DoesPackageExistAsync(packageId, packageVersion, cacheContext, logger, default);\nif (!found)\n    throw new Exception($\"Package {packageId} {packageVersion} not found on configured feeds.\");","typeGuard":null,"tryCatchPattern":"for (int attempt = 1; attempt <= 3; attempt++) {\n    using (var fs = new FileStream(packagePath, FileMode.Create, FileAccess.Write, FileShare.None)) {\n        if (await resource.CopyNupkgToStreamAsync(packageId, packageVersion, fs, cacheContext, logger, default)) {\n            Information(\"Downloaded on attempt {0}\", attempt);\n            return;\n        }\n    }\n    await Task.Delay(TimeSpan.FromSeconds(2 * attempt));\n}\nthrow new Exception(\"Failed to download the package after retries.\");","preventionTips":["Verify packageId/version against the feed before the download call.","Keep NuGet.config sources and credentials current; rotate PATs before expiry.","Clear the HTTP cache when downloads start failing persistently."],"tags":["nuget","download","network","package","dependency"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}