{"record":{"id":"23fd328084abeaf7","repo":"Unity-Technologies/UnityCsReference","slug":"assembly-with-name-loadedcustomscriptassembly-na","errorCode":null,"errorMessage":"Assembly with name '{loadedCustomScriptAssembly.Name}' already exists","messagePattern":"Assembly with name '(.+?)' already exists","errorType":"exception","errorClass":"AssemblyDefinitionException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Scripting/ScriptCompilation/LoadingAssemblyDefinition.cs","lineNumber":330,"sourceCode":"            ref CustomScriptAssembly loadedCustomScriptAssembly)\n        {\n            if (predefinedAssemblyNames.Contains(loadedCustomScriptAssembly.Name))\n            {\n                throw new AssemblyDefinitionException(\n                    $\"Assembly cannot be have reserved name '{loadedCustomScriptAssembly.Name}'\",\n                    loadedCustomScriptAssembly.FilePath);\n            }\n\n            if (assemblyLowercaseNamesLookup.TryGetValue(lowerCaseName, out var duplicate))\n            {\n                var filePaths = new[]\n                {\n                    loadedCustomScriptAssembly.FilePath,\n                    duplicate.FilePath\n                };\n                var errorMsg = $\"Assembly with name '{loadedCustomScriptAssembly.Name}' already exists\";\n                loadedCustomScriptAssembly = null; // Set to null to prevent it being added.\n                throw new AssemblyDefinitionException(errorMsg, filePaths);\n            }\n\n            // Check both asmdef and asmref files.\n            if (prefixToFilePathLookup.TryGetValue(loadedCustomScriptAssembly.PathPrefix,\n                out var duplicateFilePaths))\n            {\n                var filePaths = new List<string> {loadedCustomScriptAssembly.FilePath};\n                filePaths.AddRange(duplicateFilePaths);\n\n                throw new AssemblyDefinitionException(\n                    $\"Folder '{loadedCustomScriptAssembly.PathPrefix}' contains multiple assembly definition files\",\n                    filePaths.ToArray());\n            }\n        }\n\n        public static CustomScriptAssembly LoadCustomScriptAssemblyFromJson(string path, string json, string guid)\n        {\n            try","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Scripting/ScriptCompilation/LoadingAssemblyDefinition.cs#L312-L348","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: Assets/A/A.asmdef { \"name\": \"Shared\" }\n//         Assets/B/B.asmdef { \"name\": \"shared\" }\n// after: Assets/B/B.asmdef { \"name\": \"Shared.B\" }","handlingStrategy":"validation","validationCode":"// Enforce case-insensitive name uniqueness across all asmdefs\nvar byLowerName = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);\nforeach (var (path, name) in allAsmdefPathsWithNames)\n{\n    if (byLowerName.TryGetValue(name.ToLowerInvariant(), out var existing))\n        throw new InvalidOperationException(\n            $\"Duplicate assembly name '{name}' in {path} (already in {existing})\");\n    byLowerName[name.ToLowerInvariant()] = path;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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)."],"tags":["unity","asmdef","script-compilation","naming","duplicate","config"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}