Unity-Technologies/UnityCsReference · error · ArgumentException
assemblyPath cannot be null or empty
Error message
assemblyPath cannot be null or empty
What it means
ArgumentException from the AssemblyBuilder constructor: assemblyPath must be a non-empty string. The builder needs a real output assembly path to compile to.
Source
Thrown at Editor/Mono/Scripting/ScriptCompilation/AssemblyBuilder.cs:71
public int subtarget { get; set; }
public string[] defaultReferences => GetDefaultReferences(EditorCompilationInterface.Instance);
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);
}View on GitHub (pinned to 225b0fbdb5)
Solutions
- Compute and pass a valid absolute or relative assembly output path before constructing the builder.
- Guard the call site: reject null/empty assemblyPath upstream.
Example fix
// before var b = new AssemblyBuilder(path, scripts); // after if (string.IsNullOrEmpty(path)) throw new ArgumentNullException(nameof(path)); var b = new AssemblyBuilder(path, scripts);
Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(assemblyPath))
throw new ArgumentException("assemblyPath is required", nameof(assemblyPath)); Type guard
static bool IsValidAssemblyPath(string path) =>
!string.IsNullOrWhiteSpace(path) && path.IndexOfAny(Path.GetInvalidPathChars()) < 0; Try / catch
try { var b = new AssemblyBuilder(assemblyPath, scripts); }
catch (ArgumentException ex) when (ex.Message.Contains("assemblyPath"))
{ /* recompute a valid output path and retry */ } Prevention
- Resolve the output assembly path from a known root before constructing the builder.
- Never pass computed-but-unchecked path strings directly.
When it happens
Trigger: Constructing new AssemblyBuilder(null, ...) or new AssemblyBuilder("", ...) — passing a null or empty first argument.
Common situations: Programmatic assembly building where the output path is computed and comes back empty, or a copy-paste that drops the path argument.
Related errors
- scriptPaths 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/843b72c17dc36181.
Report an issue: GitHub.