chocolatey/choco · error · ArgumentException

File specified is either not found or not a {0} file. '{1}'

Error message

File specified is either not found or not a {0} file. '{1}'

What it means

Thrown as an ArgumentException from GetPackageFileOrThrow when the resolved file path (from config.Input or auto-discovery) does not have the expected extension or does not exist on disk. The Ensure.That call validates both the file extension matches and _fileSystem.FileExists returns true.

Source

Thrown at src/chocolatey/infrastructure.app/services/NugetService.cs:437

                config.OutputDirectory ?? _fileSystem.GetCurrentDirectory()
                                ));
        }

        public virtual string GetPackageFileOrThrow(ChocolateyConfiguration config, string extension)
        {
            Func<IFileSystem, string> getLocalFiles = (fileSystem) =>
                {
                    var filesFound = fileSystem.GetFiles(fileSystem.GetCurrentDirectory(), "*" + extension).ToList().OrEmpty();
                    Ensure.That(() => filesFound)
                          .Meets((files) => files.Count() == 1,
                                 (name, value) => { throw new FileNotFoundException("No {0} files (or more than 1) were found to build in '{1}'. Please specify the {0} file or try in a different directory.".FormatWith(extension, _fileSystem.GetCurrentDirectory())); });

                    return filesFound.FirstOrDefault();
                };

            var filePath = !string.IsNullOrWhiteSpace(config.Input) ? config.Input : getLocalFiles.Invoke(_fileSystem);
            Ensure.That(() => filePath).Meets((file) => _fileSystem.GetFileExtension(file).IsEqualTo(extension) && _fileSystem.FileExists(file),
                                              (name, value) => { throw new ArgumentException("File specified is either not found or not a {0} file. '{1}'".FormatWith(extension, value)); });

            return filePath;
        }

        public virtual void Pack(ChocolateyConfiguration config)
        {
            var nuspecFilePath = GetPackageFileOrThrow(config, PackagingConstants.ManifestExtension);
            ValidateNuspec(nuspecFilePath, config);

            var nuspecDirectory = _fileSystem.GetFullPath(_fileSystem.GetDirectoryName(nuspecFilePath));
            if (string.IsNullOrWhiteSpace(nuspecDirectory))
            {
                nuspecDirectory = _fileSystem.GetCurrentDirectory();
            }

            // Use case-insensitive properties like "nuget pack".
            var properties = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

View on GitHub (pinned to 0d5abdd10c)

Solutions

  1. Verify the file exists at the specified path using 'ls' or 'dir' before running the command.
  2. Ensure the file has the correct extension (.nuspec for pack, .nupkg for related operations).
  3. Use an absolute path to avoid relative path resolution issues.
  4. Check for typos in the file name.

Example fix

// before: file doesn't exist or wrong extension
choco pack nonexistent.nuspec   // file not found
choco pack readme.txt           // wrong extension

// after: verify and use correct file
choco pack C:\projects\myapp\myapp.nuspec
Defensive patterns

Strategy: validation

Validate before calling

// Before calling GetPackageFileOrThrow, validate the input file
if (!string.IsNullOrWhiteSpace(config.Input))
{
    if (!_fileSystem.FileExists(config.Input))
    {
        throw new InvalidOperationException($"File not found: '{config.Input}'");
    }
    if (!_fileSystem.GetFileExtension(config.Input).IsEqualTo(extension))
    {
        throw new InvalidOperationException($"File '{config.Input}' does not have extension '{extension}'");
    }
}

Type guard

public static bool IsValidPackageFile(string filePath, string expectedExtension, IFileSystem fileSystem)
{
    return !string.IsNullOrWhiteSpace(filePath)
        && fileSystem.FileExists(filePath)
        && fileSystem.GetFileExtension(filePath).IsEqualTo(expectedExtension);
}

Try / catch

try
{
    var packageFile = _nugetService.GetPackageFileOrThrow(config, extension);
}
catch (ArgumentException ex) when (ex.Message.Contains("not found or not a"))
{
    logger.Error($"Invalid file specified: {ex.Message}. Verify the path and extension.");
}

Prevention

When it happens

Trigger: Calling GetPackageFileOrThrow with config.Input set to a path that either (a) does not end with the expected extension (e.g., passing a .txt file when .nuspec is expected), or (b) refers to a file that does not exist on disk. The validation runs after the getLocalFiles auto-discovery step.

Common situations: A user runs 'choco pack wrongfile.txt' or 'choco pack nonexistent.nuspec'. The file must both exist and have the correct extension. Also triggered by typos in the file name or relative path issues.

Related errors


AI-assisted analysis of chocolatey/choco@0d5abdd10c (2026-08-13). Data as JSON: /api/errors/90d9634de4fa02a5. Report an issue: GitHub.