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
- 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.
- 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
- Validate .asmdef JSON against Unity's asmdef schema before feeding it to the loader.
- When generating asmdefs programmatically, round-trip them through the schema validator first.
- Always inspect ex.filePaths to attribute the failure to the correct source file.
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
- Both 'excludePlatforms' and 'includePlatforms' are set.
- Assembly '{name}' is a CodeGen assembly and cannot be Auto R
- Invalid Define Constraint: "{DefineConstraints[i]}" at line
- Platform name '{0}' not supported. Supported platform names:
- Assembly has duplicate references: {duplicateRefsString}
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/2ba26b010f2755c7.
Report an issue: GitHub.