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

  1. Compute and pass a valid absolute or relative assembly output path before constructing the builder.
  2. 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

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


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