Unity-Technologies/UnityCsReference · error · AssemblyDefinitionException
Assembly cannot be have reserved name '{loadedCustomScriptAs
Error message
Assembly cannot be have reserved name '{loadedCustomScriptAssembly.Name}' What it means
Thrown by CheckPredefinedAssemblyNames (LoadingAssemblyDefinition.cs:316) when an asmdef's 'name' matches an entry in predefinedAssemblyNames. That set is built from EditorBuildRules.PredefinedTargetAssemblyNames (Unity's built-in/predefined assemblies) plus, depending on the target framework, the .NET Framework / .NET Standard 2.1 reference assemblies. These names are reserved so user assemblies cannot shadow or alias the framework's own assemblies.
Source
Thrown at Editor/Mono/Scripting/ScriptCompilation/LoadingAssemblyDefinition.cs:316
Exceptions = exceptions.ToArray();
}
public void ClearCustomScriptAssemblies()
{
CustomScriptAssemblies = Array.Empty<CustomScriptAssembly>();
CustomScriptAssemblyReferences.Clear();
}
static void CheckPredefinedAssemblyNames(
HashSet<string> predefinedAssemblyNames,
Dictionary<string, CustomScriptAssembly> assemblyLowercaseNamesLookup,
string lowerCaseName,
Dictionary<string, List<string>> prefixToFilePathLookup,
ref CustomScriptAssembly loadedCustomScriptAssembly)
{
if (predefinedAssemblyNames.Contains(loadedCustomScriptAssembly.Name))
{
throw new AssemblyDefinitionException(
$"Assembly cannot be have reserved name '{loadedCustomScriptAssembly.Name}'",
loadedCustomScriptAssembly.FilePath);
}
if (assemblyLowercaseNamesLookup.TryGetValue(lowerCaseName, out var duplicate))
{
var filePaths = new[]
{
loadedCustomScriptAssembly.FilePath,
duplicate.FilePath
};
var errorMsg = $"Assembly with name '{loadedCustomScriptAssembly.Name}' already exists";
loadedCustomScriptAssembly = null; // Set to null to prevent it being added.
throw new AssemblyDefinitionException(errorMsg, filePaths);
}
// Check both asmdef and asmref files.
if (prefixToFilePathLookup.TryGetValue(loadedCustomScriptAssembly.PathPrefix,View on GitHub (pinned to 225b0fbdb5)
Solutions
- Rename the asmdef to a value not present among predefined/framework assembly names (prefix with your company/package name).
- If the name was chosen to 'replace' a built-in assembly, that is unsupported; instead reference the built-in assembly and extend it.
Example fix
// before (.asmdef)
{ "name": "System" }
// after
{ "name": "MyCompany.SystemExtensions" } Defensive patterns
Strategy: validation
Validate before calling
// Reject reserved/framework assembly names before importing
static readonly HashSet<string> Reserved = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"UnityEngine","UnityEditor","mscorlib","System","System.Core","System.Xml",
"netstandard","System.Net.Http"
};
if (Reserved.Contains(data.name))
throw new InvalidOperationException(
$"'{data.name}' is a reserved/framework assembly name; rename it."); Prevention
- Prefix asmdef names with a company/package namespace.
- Never name an asmdef after a BCL or built-in Unity assembly.
- Cross-check candidate names against EditorBuildRules.PredefinedTargetAssemblyNames when authoring tooling.
When it happens
Trigger: Naming an asmdef "UnityEngine", "UnityEditor", "mscorlib", "System", "System.Core", "netstandard", or any other predefined/framework assembly name.
Common situations: Accidentally naming a wrapper assembly after the framework it wraps. Package naming collisions with BCL assemblies. Copying internal Unity assembly names into a project.
Related errors
- Assembly '{name}' is a CodeGen assembly and cannot be Auto R
- Assembly with name '{loadedCustomScriptAssembly.Name}' alrea
- Both 'excludePlatforms' and 'includePlatforms' are set.
- Invalid Define Constraint: "{DefineConstraints[i]}" at line
- Platform name '{0}' not supported. Supported platform names:
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/e5c6bf52f623b8ab.
Report an issue: GitHub.