chocolatey/choco · error · Exception

Custom unofficial builds are not allowed by default. To ov

Error message

Custom unofficial builds are not allowed by default.
 To override this behavior, explicitly set --allow-unofficial.
 See the help menu (choco --help) for options.

What it means

Thrown by GenericRunner when the executing assembly's public key token does not match ApplicationParameters.OfficialChocolateyPublicKey (i.e., it is a custom/unofficial build) and config.AllowUnofficialBuild is false. Chocolatey enforces build authenticity by checking the strong-name signing token, preventing unofficially compiled binaries from running by default. This is a security/trust measure.

Source

Thrown at src/chocolatey/infrastructure.app/runners/GenericRunner.cs:99

                EnvironmentSettings.SetEnvironmentVariables(config);

                this.Log().Debug(() => "Configuration: {0}".FormatWith(config.ToString()));

                if (isConsole && (config.HelpRequested || config.UnsuccessfulParsing))
                {
#if DEBUG
                    Console.WriteLine("Press enter to continue...");
                    Console.ReadKey();
#endif
                    Environment.Exit(config.UnsuccessfulParsing ? 1 : 0);
                }

                var token = Assembly.GetExecutingAssembly().GetPublicKeyToken();
                if (string.IsNullOrWhiteSpace(token) || !token.IsEqualTo(ApplicationParameters.OfficialChocolateyPublicKey))
                {
                    if (!config.AllowUnofficialBuild)
                    {
                        throw new Exception(@"
Custom unofficial builds are not allowed by default.
 To override this behavior, explicitly set --allow-unofficial.
 See the help menu (choco --help) for options.");
                    }
                    else
                    {
                        this.Log().Warn(config.RegularOutput ? ChocolateyLoggers.Important : ChocolateyLoggers.LogFileOnly, @"
Chocolatey is not an official build (bypassed with --allow-unofficial).
 If you are seeing this message and it is not expected, your system may
 now be in a bad state. Only official builds are to be trusted.
"
                        );
                    }
                }
            }

            return command;
        }

View on GitHub (pinned to 0d5abdd10c)

Solutions

  1. If this is intentional (development/testing), pass --allow-unofficial to bypass the check
  2. Use an official Chocolatey build downloaded from the official source for production
  3. Sign the custom build with the official key if you have access (internal Chocolatey team only)
  4. Set config.AllowUnofficialBuild = true programmatically for test harnesses

Example fix

// before (custom build)
choco install mypackage
// throws: Custom unofficial builds are not allowed by default.

// after (custom build - explicit opt-in)
choco install mypackage --allow-unofficial
Defensive patterns

Strategy: validation

Validate before calling

// For custom builds, set AllowUnofficialBuild before running
if (!IsOfficialBuild())
{
    config.AllowUnofficialBuild = true;
    Console.Warning("Running unofficial build. Set --allow-unofficial to proceed.");
}
// CLI: always pass --allow-unofficial for dev builds
// choco install mypackage --allow-unofficial

Try / catch

try
{
    runner.Run(config, container, isConsole, parseArgs);
}
catch (Exception ex) when (ex.Message.Contains("unofficial"))
{
    logger.Error("Unofficial build detected. Add --allow-unofficial to bypass.");
    Environment.Exit(1);
}

Prevention

When it happens

Trigger: Running a self-compiled or modified Chocolatey binary without the official signing key. Running a debug or dev build. Running a fork or custom build without explicitly opting in. The assembly has no public key token at all (unsigned). The token differs from the official key.

Common situations: Developer builds Chocolatey from source for testing or contribution. CI pipeline compiles and runs Chocolatey from a PR branch. Fork maintainer distributes a custom build. Someone runs a tampered or unofficially modified binary.

Related errors


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