Unity-Technologies/UnityCsReference · error · ArgumentException

Non-development build cannot allow code coverage. Either add

Error message

Non-development build cannot allow code coverage. Either add the Development build option, or remove the EnableCodeCoverage build option.

What it means

Thrown when BuildPlayer is called with BuildOptions.EnableCodeCoverage set but BuildOptions.Development is NOT set. Code coverage instrumentation requires the Development build pipeline because it injects coverage probes and links against coverage-specific runtime libraries.

Source

Thrown at Editor/Mono/BuildPipeline/BuildPipeline.bindings.cs:239

                    throw new InvalidOperationException("The build cannot be appended.");
            }

            if (buildPlayerOptions.scenes != null)
            {
                for (int i = 0; i < buildPlayerOptions.scenes.Length; i++)
                    buildPlayerOptions.scenes[i] = buildPlayerOptions.scenes[i].Replace('\\', '/').Replace("//", "/");
            }

            if ((buildPlayerOptions.options & BuildOptions.Development) == 0)
            {
                if ((buildPlayerOptions.options & BuildOptions.AllowDebugging) != 0)
                {
                    throw new ArgumentException("Non-development build cannot allow debugging. Either add the Development build option, or remove the AllowDebugging build option.");
                }

                if ((buildPlayerOptions.options & BuildOptions.EnableCodeCoverage) != 0)
                {
                    throw new ArgumentException("Non-development build cannot allow code coverage. Either add the Development build option, or remove the EnableCodeCoverage build option.");
                }

                if ((buildPlayerOptions.options & BuildOptions.EnableDeepProfilingSupport) != 0)
                {
                    throw new ArgumentException("Non-development build cannot allow deep profiling support. Either add the Development build option, or remove the EnableDeepProfilingSupport build option.");
                }

                if ((buildPlayerOptions.options & BuildOptions.ConnectWithProfiler) != 0)
                {
                    throw new ArgumentException("Non-development build cannot allow auto-connecting the profiler. Either add the Development build option, or remove the ConnectWithProfiler build option.");
                }
            }
            else
            {
                if ((buildPlayerOptions.options & BuildOptions.EnableCodeCoverage) != 0)
                {
                    if (!BuildProfileModuleUtil.IsBuildTargetSupportedByCoverage(buildPlayerOptions.target))
                        throw new ArgumentException("Code coverage is unavailable for the selected build target. Remove the EnableCodeCoverage build option.");

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Add BuildOptions.Development to the options bitmask alongside EnableCodeCoverage.
  2. Remove BuildOptions.EnableCodeCoverage if the build is intended to be a non-development release build.
  3. Use a validation helper that enforces the Development prerequisite before calling BuildPlayer.

Example fix

// before
var options = new BuildPlayerOptions
{
    options = BuildOptions.EnableCodeCoverage,
    target = BuildTarget.StandaloneWindows64
};
BuildPipeline.BuildPlayer(options);

// after
var options = new BuildPlayerOptions
{
    options = BuildOptions.Development | BuildOptions.EnableCodeCoverage,
    target = BuildTarget.StandaloneWindows64
};
BuildPipeline.BuildPlayer(options);
Defensive patterns

Strategy: validation

Validate before calling

BuildOptions EnsureDevelopmentForDevOnlyFlags(BuildOptions options)
{
    BuildOptions devOnlyFlags = BuildOptions.AllowDebugging |
        BuildOptions.EnableCodeCoverage |
        BuildOptions.EnableDeepProfilingSupport |
        BuildOptions.ConnectWithProfiler;

    if ((options & devOnlyFlags) != 0 && (options & BuildOptions.Development) == 0)
        options |= BuildOptions.Development;
    return options;
}

// Before BuildPlayer:
options.options = EnsureDevelopmentForDevOnlyFlags(options.options);

Prevention

When it happens

Trigger: Calling BuildPipeline.BuildPlayer with options that include EnableCodeCoverage without Development — e.g., BuildOptions.EnableCodeCoverage alone or combined with non-development flags.

Common situations: CI pipelines that enable code coverage for automated test runs but fail to set the Development flag, or build configurations migrated from a development preset where the Development flag was accidentally removed.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/ab5e59ede2961d91. Report an issue: GitHub.