{"record":{"id":"ffdb46b3f4bc1588","repo":"chocolatey/choco","slug":"package-path-not-a-nupkg-or-nuspec","errorCode":null,"errorMessage":"Package Path not a .nupkg or .nuspec","messagePattern":"Package Path not a \\.nupkg or \\.nuspec","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/chocolatey/infrastructure.app/domain/ChocolateyPackageMetadata.cs","lineNumber":154,"sourceCode":"                DevelopmentDependency = reader.GetDevelopmentDependency();\r\n                Description = reader.GetDescription();\r\n                Summary = reader.GetSummary();\r\n                ReleaseNotes = reader.GetReleaseNotes();\r\n                Language = reader.GetLanguage();\r\n                Tags = reader.GetTags();\r\n                Serviceable = reader.IsServiceable();\r\n                Copyright = reader.GetCopyright();\r\n                Icon = reader.GetIcon();\r\n                Readme = reader.GetReadme();\r\n                DependencyGroups = reader.GetDependencyGroups();\r\n                PackageTypes = reader.GetPackageTypes();\r\n                Repository = reader.GetRepositoryMetadata();\r\n                LicenseMetadata = reader.GetLicenseMetadata();\r\n                FrameworkReferenceGroups = reader.GetFrameworkRefGroups();\r\n            }\r\n            else\r\n            {\r\n                throw new ArgumentException(\"Package Path not a .nupkg or .nuspec\");\r\n            }\r\n        }\r\n\r\n        public Uri ProjectSourceUrl { get; }\r\n        public Uri PackageSourceUrl { get; }\r\n        public Uri DocsUrl { get; }\r\n        public Uri WikiUrl { get; }\r\n        public Uri MailingListUrl { get; }\r\n        public Uri BugTrackerUrl { get; }\r\n        public IEnumerable<string> Replaces { get; }\r\n        public IEnumerable<string> Provides { get; }\r\n        public IEnumerable<string> Conflicts { get; }\r\n        public string SoftwareDisplayName { get; }\r\n        public string SoftwareDisplayVersion { get; }\r\n        public string Id { get; }\r\n        public NuGetVersion Version { get; private set; }\r\n        public string Title { get; }\r\n        public IEnumerable<string> Authors { get; }\r","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/chocolatey/choco/blob/0d5abdd10cc177a141e69547cad6935b419b6c17/src/chocolatey/infrastructure.app/domain/ChocolateyPackageMetadata.cs#L136-L172","documentation":"Thrown by the ChocolateyPackageMetadata constructor when the provided packagePath does not have a .nupkg extension (checked via NuGetConstants.PackageExtension) and does not have a .nuspec extension (NuGetConstants.ManifestExtension). The constructor only knows how to read metadata from these two file formats using NuGet's PackageArchiveReader and NuspecReader respectively. Any other file type or path is rejected before attempting to parse.","triggerScenarios":"Passing a path to a .zip, .config, .xml, or any non-.nupkg/.nuspec file to the ChocolateyPackageMetadata constructor. Passing a directory path instead of a file path. Passing a file with no extension. Passing a corrupt path where GetFileExtension returns something unexpected.","commonSituations":"Automated packaging pipeline passes the wrong file path (e.g. the build output .dll instead of the .nupkg). User renames a .nupkg to .zip for inspection and then accidentally passes the .zip. Script constructs a path by string concatenation and introduces a typo or missing extension. Unpacking step creates intermediate files that get picked up by a glob.","solutions":["Verify the file path ends in .nupkg or .nuspec before constructing ChocolateyPackageMetadata","Check that the path points to an actual file and not a directory","Ensure packaging build completed successfully and produced the expected .nupkg output","Add a file extension check: if (!path.EndsWith(\".nupkg\") && !path.EndsWith(\".nuspec\")) return error"],"exampleFix":"// before\nvar metadata = new ChocolateyPackageMetadata(@\"C:\\packages\\mytool-1.0.zip\");\n\n// after\nvar metadata = new ChocolateyPackageMetadata(@\"C:\\packages\\mytool-1.0.nupkg\");\n\n// defensive check\nvar path = @\"C:\\packages\\mytool-1.0\";\nvar nupkg = Directory.GetFiles(path, \"*.nupkg\").FirstOrDefault();\nif (nupkg != null)\n    var metadata = new ChocolateyPackageMetadata(nupkg);","handlingStrategy":"validation","validationCode":"// Validate file extension before constructing ChocolateyPackageMetadata\nvar ext = Path.GetExtension(packagePath)?.ToLowerInvariant();\nif (ext != \".nupkg\" && ext != \".nuspec\")\n{\n    throw new ArgumentException($\"Expected .nupkg or .nuspec file, got: {packagePath}\");\n}\nif (!File.Exists(packagePath))\n{\n    throw new FileNotFoundException($\"Package file not found: {packagePath}\");\n}","typeGuard":"public static bool IsValidPackageFile(string path)\n{\n    if (string.IsNullOrWhiteSpace(path)) return false;\n    var ext = Path.GetExtension(path)?.ToLowerInvariant();\n    return ext == \".nupkg\" || ext == \".nuspec\";\n}","tryCatchPattern":"try\n{\n    var metadata = new ChocolateyPackageMetadata(packagePath, filesystem);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\".nupkg or .nuspec\"))\n{\n    logger.Error($\"Invalid package file: {packagePath}. Must be .nupkg or .nuspec.\");\n    // Find the correct file in the directory\n}","preventionTips":["Always verify the file extension before passing a path to ChocolateyPackageMetadata","Use Directory.GetFiles(dir, \"*.nupkg\") to discover valid package files","Validate File.Exists before construction to catch path errors early","In CI pipelines, ensure the build produces .nupkg output before attempting metadata extraction"],"tags":["validation","package-metadata","file-extension","nupkg","nuspec"],"backgroundTag":null,"analyzedSha":"0d5abdd10cc177a141e69547cad6935b419b6c17","analyzedAt":"2026-08-13T18:33:03.301Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}