Unity-Technologies/UnityCsReference · error · AssemblyDefinitionException

<relayed from caught exception: e.Message, FilePath=path>

Error message

<relayed from caught exception: e.Message, FilePath=path>

What it means

LoadCustomScriptAssemblyFromJson (LoadingAssemblyDefinition.cs:355) wraps ANY exception thrown while deserializing an asmdef's JSON and building the CustomScriptAssembly (e.g. JSON parse errors, or the validation failures from errors 700/701/702/703) into an AssemblyDefinitionException whose filePaths carries the source .asmdef path. The original cause is only preserved as the wrapped exception's Message string, not its stack/type.

Source

Thrown at Editor/Mono/Scripting/ScriptCompilation/LoadingAssemblyDefinition.cs:355

                var filePaths = new List<string> {loadedCustomScriptAssembly.FilePath};
                filePaths.AddRange(duplicateFilePaths);

                throw new AssemblyDefinitionException(
                    $"Folder '{loadedCustomScriptAssembly.PathPrefix}' contains multiple assembly definition files",
                    filePaths.ToArray());
            }
        }

        public static CustomScriptAssembly LoadCustomScriptAssemblyFromJson(string path, string json, string guid)
        {
            try
            {
                var customScriptAssemblyData = CustomScriptAssemblyData.FromJson(json);
                return CustomScriptAssembly.FromCustomScriptAssemblyData(path, guid, customScriptAssemblyData);
            }
            catch (Exception e)
            {
                throw new AssemblyDefinitionException(e.Message, path);
            }
        }

        public static CustomScriptAssembly LoadCustomScriptAssemblyFromJsonPath(string path, string guid)
        {
            var json = Utility.ReadTextAsset(path);

            try
            {
                var customScriptAssemblyData = CustomScriptAssemblyData.FromJson(json);
                return CustomScriptAssembly.FromCustomScriptAssemblyData(path, guid, customScriptAssemblyData);
            }
            catch (Exception e)
            {
                throw new AssemblyDefinitionException(e.Message, path);
            }
        }

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Read the AssemblyDefinitionException.Message (it relays the inner exception's message) and the filePaths[0] to locate the offending asmdef, then fix the underlying content issue described by that inner message.
  2. Validate the .asmdef JSON with a JSON linter and Unity's asmdef schema before reimporting.
Defensive patterns

Strategy: try-catch

Try / catch

try
{
    var asm = CustomScriptAssembly.LoadCustomScriptAssemblyFromJson(path, json, guid);
}
catch (AssemblyDefinitionException ex)
{
    // ex.Message relays the inner cause; ex.filePaths[0] is the .asmdef path
    LogError($"Failed to load asmdef '{string.Join(", ", ex.filePaths)}': {ex.Message}");
    // surface to the user as an import error; do not swallow
}

Prevention

When it happens

Trigger: Malformed .asmdef JSON, a missing 'name', a failed ValidateFields (both platform arrays set, codegen+autoReferenced), or an invalid define constraint / platform name encountered while loading from a JSON string.

Common situations: Hand-editing an asmdef and introducing a syntax error. External tooling writing invalid asmdef JSON. Copying a partial asmdef.

Related errors


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