Unity-Technologies/UnityCsReference · error · AssemblyDefinitionException

Folder '{loadedCustomScriptAssembly.PathPrefix}' contains mu

Error message

Folder '{loadedCustomScriptAssembly.PathPrefix}' contains multiple assembly definition files

What it means

Thrown by CheckPredefinedAssemblyNames (LoadingAssemblyDefinition.cs:340) when an assembly's PathPrefix is already present in prefixToFilePathLookup. PathPrefix is the owning folder of an assembly definition. Unity forbids more than one assembly-definition file per folder prefix (across .asmdef and .asmref), so a collision here means two assembly definitions claim the same folder scope. The message lists the colliding file paths.

Source

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

            {
                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)
        {
            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. Keep only one assembly-definition file per folder; move the second .asmdef into a subfolder.
  2. Delete the duplicate assembly-definition file if it was created unintentionally.

Example fix

// before: Assets/MyLib/A.asmdef and Assets/MyLib/B.asmdef
// after: Assets/MyLib/A.asmdef  and  Assets/MyLib/Sub/B.asmdef
Defensive patterns

Strategy: validation

Validate before calling

// Same folder-prefix collision check as 705, applied to .asmdef files
var byPrefix = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
foreach (var f in allAsmdefPaths)
    (byPrefix[System.IO.Path.GetDirectoryName(f)?.Replace('\\','/')] ??= new List<string>()).Add(f);

var dup = byPrefix.FirstOrDefault(kv => kv.Value.Count > 1);
if (dup.Value != null)
    throw new InvalidOperationException($"Folder '{dup.Key}' has multiple asmdef files: {string.Join(", ", dup.Value)}");

Prevention

When it happens

Trigger: Two .asmdef files in the same folder, or an .asmdef plus an .asmref whose prefixes resolve identically. Same root cause as error 705 but detected while validating the primary assembly rather than a reference.

Common situations: Placing a second asmdef in a folder that already has one. Copying an asmdef into an existing assembly's folder.

Related errors


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