Unity-Technologies/UnityCsReference · error · ArgumentException
scriptPaths cannot be null or empty
Error message
scriptPaths cannot be null or empty
What it means
ArgumentException from the AssemblyBuilder constructor: the scriptPaths params array must be non-null and non-empty. The builder cannot compile with zero source files.
Source
Thrown at Editor/Mono/Scripting/ScriptCompilation/AssemblyBuilder.cs:74
public string[] defaultDefines => GetDefaultDefines(EditorCompilationInterface.Instance);
private class BeeScriptCompilationState
{
public ScriptAssembly[] assemblies;
public ActiveBuild ActiveBuild;
public EditorCompilation editorCompilation;
public bool finishedCompiling;
}
private BeeScriptCompilationState activeBeeBuild;
public AssemblyBuilder(string assemblyPath, params string[] scriptPaths)
{
if (string.IsNullOrEmpty(assemblyPath))
throw new ArgumentException("assemblyPath cannot be null or empty");
if (scriptPaths == null || scriptPaths.Length == 0)
throw new ArgumentException("scriptPaths cannot be null or empty");
this.scriptPaths = scriptPaths;
this.assemblyPath = assemblyPath;
compilerOptions = new ScriptCompilerOptions();
flags = AssemblyBuilderFlags.None;
referencesOptions = ReferencesOptions.None;
buildTargetGroup = EditorUserBuildSettings.activeBuildTargetGroup;
buildTarget = EditorUserBuildSettings.activeBuildTarget;
}
public bool Build()
{
return Build(EditorCompilationInterface.Instance);
}
internal bool Build(EditorCompilation editorCompilation)
{View on GitHub (pinned to 225b0fbdb5)
Solutions
- Ensure at least one source file is collected before constructing the builder.
- Null/length-check the scriptPaths array at the call site.
Example fix
// before
var b = new AssemblyBuilder(path, scripts);
// after
if (scripts == null || scripts.Length == 0) throw new ArgumentException("No scripts to compile", nameof(scripts));
var b = new AssemblyBuilder(path, scripts); Defensive patterns
Strategy: validation
Validate before calling
if (scriptPaths == null || scriptPaths.Length == 0)
throw new ArgumentException("At least one script path is required", nameof(scriptPaths)); Type guard
static bool HasScripts(string[] paths) => paths != null && paths.Length > 0;
Try / catch
try { var b = new AssemblyBuilder(assemblyPath, scripts); }
catch (ArgumentException ex) when (ex.Message.Contains("scriptPaths"))
{ /* collect actual source files and retry */ } Prevention
- Verify your file glob returned matches before building.
- Treat an empty source set as a configuration error, not a no-op.
When it happens
Trigger: Constructing new AssemblyBuilder(path) with no script files, or passing a null array / empty array as scriptPaths.
Common situations: Building an assembly from a glob that matched nothing, or omitting the script paths argument.
Related errors
- assemblyPath cannot be null or empty
- Invalid argument {0} provided.
- {reference} is not a GUID reference
- Cannot start AssemblyBuilder with status {0}. Expected {1}
- targetCacheSize should be >= 0, got {targetCacheSize}
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/c22e2fc4c7d57703.
Report an issue: GitHub.