Unity-Technologies/UnityCsReference · error · AssemblyDefinitionException
Assembly with name '{loadedCustomScriptAssembly.Name}' alrea
Error message
Assembly with name '{loadedCustomScriptAssembly.Name}' already exists What it means
Thrown by CheckPredefinedAssemblyNames (LoadingAssemblyDefinition.cs:330) when the lowercased form of a newly loaded assembly's name already exists in assemblyLowercaseNamesLookup, i.e. another asmdef already registered that name. Name uniqueness is enforced case-insensitively because assembly resolution on case-insensitive filesystems must be deterministic. The message reports both colliding file paths.
Source
Thrown at Editor/Mono/Scripting/ScriptCompilation/LoadingAssemblyDefinition.cs:330
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,
out var duplicateFilePaths))
{
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)
{
tryView on GitHub (pinned to 225b0fbdb5)
Solutions
- Rename one of the two asmdefs so both names are unique (case-insensitively), prefixing with a namespace/package identifier.
- If the duplicate is unintentional, delete the stray .asmdef file.
Example fix
// before: Assets/A/A.asmdef { "name": "Shared" }
// Assets/B/B.asmdef { "name": "shared" }
// after: Assets/B/B.asmdef { "name": "Shared.B" } Defensive patterns
Strategy: validation
Validate before calling
// Enforce case-insensitive name uniqueness across all asmdefs
var byLowerName = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
foreach (var (path, name) in allAsmdefPathsWithNames)
{
if (byLowerName.TryGetValue(name.ToLowerInvariant(), out var existing))
throw new InvalidOperationException(
$"Duplicate assembly name '{name}' in {path} (already in {existing})");
byLowerName[name.ToLowerInvariant()] = path;
} Prevention
- Give every asmdef a globally unique, namespaced name.
- When copying an asmdef to fork it, rename immediately.
- Add a CI uniqueness check over asmdef 'name' fields (case-insensitive).
When it happens
Trigger: Two .asmdef files whose 'name' fields match ignoring case, e.g. "MyLib" and "mylib". Copying an asmdef to a new folder to fork it without renaming.
Common situations: Duplicating an asmdef to create a variant and forgetting to rename. Cross-platform casing differences. Package A and Package B both shipping an asmdef with the same generic name.
Related errors
- Assembly cannot be have reserved name '{loadedCustomScriptAs
- Folder '{loadedCustomScriptAssembly.PathPrefix}' contains mu
- Both 'excludePlatforms' and 'includePlatforms' are set.
- Assembly '{name}' is a CodeGen assembly and cannot be Auto R
- Invalid Define Constraint: "{DefineConstraints[i]}" at line
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/23fd328084abeaf7.
Report an issue: GitHub.