chocolatey/choco · error · ApplicationException
Package name cannot be a path to a file
Error message
Package name cannot be a path to a file
What it means
Thrown as an ApplicationException from ThrowInvalidPathError when a package name ending in '.nupkg' resolves to a valid local file or UNC path. Unlike error 68 (where the file does not exist), this fires when the file IS found — the user is pointing to a specific .nupkg file instead of using --source. The message includes a contextual usage example built by BuildInstallExample showing the correct choco command syntax.
Source
Thrown at src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs:1373
sb.AppendLine("on a UNC location.")
.AppendLine()
.Append("To ")
.Append(commandName.ToLowerSafe())
.AppendLine(" a file in a UNC location, you may use:");
}
else
{
sb.AppendLine("on a remote, or local file system.")
.AppendLine()
.Append("To ")
.Append(commandName.ToLowerSafe())
.AppendLine(" a local, or remote file, you may use:");
}
BuildInstallExample(packageName, sb, commandName.ToLowerSafe());
throw new ApplicationException(sb.AppendLine().ToString());
}
private void BuildInstallExample(string packageName, StringBuilder sb, string commandName)
{
var fileName = _fileSystem.GetFilenameWithoutExtension(packageName);
var version = string.Empty;
// We need to get the directory name in this way in case it is a UNC path.
// Using normal way to get the directory name may trim out parts of the necessary path.
var length = packageName.Length - _fileSystem.GetFileName(packageName).Length - 1;
var directory = length > 0 ? packageName.Substring(0, length) : string.Empty;
if (fileName.Contains('.'))
{
var originalFileName = fileName;
fileName = string.Empty;
while (fileName.Length < originalFileName.Length)
{
View on GitHub (pinned to 0d5abdd10c)
Solutions
- Follow the generated example in the error message — it shows the exact correct command for your scenario.
- Use --source to point to the directory containing the .nupkg and pass the package name without path or extension.
- For UNC paths: 'choco install firefox --source=\\server\share\packages'.
- For local paths: 'choco install firefox --source=C:\downloads'.
Example fix
// before: pointing package name at a specific .nupkg file choco install C:\downloads\firefox.1.0.0.nupkg // after: use --source for the directory, package name only choco install firefox --source=C:\downloads // the error message itself generates this example dynamically
Defensive patterns
Strategy: validation
Validate before calling
// Detect file-path package names and redirect before the API throws
foreach (var name in config.PackageNames.Split(';'))
{
if (name.EndsWith(".nupkg", StringComparison.OrdinalIgnoreCase))
{
if (Uri.TryCreate(name, UriKind.Absolute, out var uri) && (uri.IsFile || uri.IsUnc))
{
var dir = Path.GetDirectoryName(uri.LocalPath);
var pkgId = Path.GetFileNameWithoutExtension(uri.LocalPath);
throw new InvalidOperationException($"Use: choco install {pkgId} --source={dir}");
}
if (_fileSystem.FileExists(name))
{
var dir = Path.GetDirectoryName(_fileSystem.GetFullPath(name));
var pkgId = _fileSystem.GetFilenameWithoutExtension(name);
throw new InvalidOperationException($"Use: choco install {pkgId} --source={dir}");
}
}
} Try / catch
try
{
_packageService.Install(config);
}
catch (ApplicationException ex) when (ex.Message.Contains("Package name cannot be a path to a file"))
{
// The error message already contains a generated usage example
logger.Error(ex.Message); // shows the correct 'choco install ... --source=...' command
} Prevention
- Always use --source to specify the directory containing .nupkg files, never the file path itself.
- For UNC paths, format as: choco install pkgname --source=\\server\share\dir.
- The error message itself generates the correct command — read it and follow the suggestion.
When it happens
Trigger: ValidatePackageNames detects a .nupkg package name that Uri.TryCreate resolves to a file:// or UNC URI, or that _fileSystem.FileExists confirms exists. ThrowInvalidPathError is called with the resolved path and UNC flag, building a detailed message with a correct usage example before throwing.
Common situations: A user runs 'choco install C:\downloads\firefox.nupkg' or 'choco install \\server\share\firefox.nupkg'. Chocolatey identifies the file path but rejects it, instead showing the correct command: 'choco install firefox --source=C:\downloads'.
Related errors
- Package name cannot point directly to a local, or remote fil
- Package name cannot point directly to a package manifest fil
- A single package name is required to run the choco info comm
- Only a single package name can be passed to the choco info c
- Package name is required. Please pass at least one package n
AI-assisted analysis of chocolatey/choco@0d5abdd10c (2026-08-13).
Data as JSON: /api/errors/5be6e7513017f312.
Report an issue: GitHub.