Unity-Technologies/UnityCsReference · error · ArgumentException
Invalid argument {0} provided.
Error message
Invalid argument {0} provided. What it means
ArgumentException from the CodeOptimization setter's switch: the supplied value is not Debug or Release. The default branch rejects any other CodeOptimization value.
Source
Thrown at Editor/Mono/Scripting/ScriptCompilation/CompilationPipeline.cs:280
}
switch (value)
{
case CodeOptimization.Debug:
{
EnableScriptDebugInfo();
break;
}
case CodeOptimization.Release:
{
DisableScriptDebugInfo();
break;
}
default:
{
throw new ArgumentException(string.Format("Invalid argument {0} provided.", value.ToString()));
}
}
}
}
internal static bool TryGetLastBuildResult(CompileTarget target, out CompilationDoneResult? lastCompilationDoneResult)
{
if (MsBuildCompilationInterface.Instance.TryGetLastBuildResult(target, out var result))
{
lastCompilationDoneResult = result;
return true;
}
lastCompilationDoneResult = null;
return false;
}
internal static void ReportBuildFinished(CompileTarget target, CompilationDoneResult compilationDoneResult)View on GitHub (pinned to 225b0fbdb5)
Solutions
- Map to CodeOptimization.Debug or CodeOptimization.Release explicitly.
- Validate the incoming value before assignment.
Example fix
// before SetCodeOptimization(userValue); // after var v = (userValue == CodeOptimization.Release) ? CodeOptimization.Release : CodeOptimization.Debug; SetCodeOptimization(v);
Defensive patterns
Strategy: validation
Validate before calling
if (value != CodeOptimization.Debug && value != CodeOptimization.Release)
throw new ArgumentOutOfRangeException(nameof(value), $"Unsupported CodeOptimization: {value}"); Type guard
static bool IsSupported(CodeOptimization c) =>
c == CodeOptimization.Debug || c == CodeOptimization.Release; Prevention
- Normalize unknown CodeOptimization values to Debug or Release before assignment.
- Avoid default(CodeOptimization) unless it equals one of the supported members.
When it happens
Trigger: Assigning a CodeOptimization value other than Debug or Release to the property (e.g. an undefined/None enum member).
Common situations: Passing an uninitialized or newly added CodeOptimization value, or default(CodeOptimization) when that is neither Debug nor Release.
Related errors
- assemblyPath cannot be null or empty
- scriptPaths cannot be null or empty
- {reference} is not a GUID reference
- Unknown WSA image type: {type}
- Unknown image scale: {scale}
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/57553649fb9cb3f1.
Report an issue: GitHub.