{"record":{"id":"7fe8f53fefdb7aee","repo":"Unity-Technologies/UnityCsReference","slug":"folder-loadedcustomscriptassembly-pathprefix-c","errorCode":null,"errorMessage":"Folder '{loadedCustomScriptAssembly.PathPrefix}' contains multiple assembly definition files","messagePattern":"Folder '(.+?)' contains multiple assembly definition files","errorType":"exception","errorClass":"AssemblyDefinitionException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Scripting/ScriptCompilation/LoadingAssemblyDefinition.cs","lineNumber":340,"sourceCode":"            {\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\n            {\n                var customScriptAssemblyData = CustomScriptAssemblyData.FromJson(json);\n                return CustomScriptAssembly.FromCustomScriptAssemblyData(path, guid, customScriptAssemblyData);\n            }\n            catch (Exception e)\n            {\n                throw new AssemblyDefinitionException(e.Message, path);\n            }\n        }\n","sourceCodeStart":322,"sourceCodeEnd":358,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Scripting/ScriptCompilation/LoadingAssemblyDefinition.cs#L322-L358","documentation":"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.","triggerScenarios":"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.","commonSituations":"Placing a second asmdef in a folder that already has one. Copying an asmdef into an existing assembly's folder.","solutions":["Keep only one assembly-definition file per folder; move the second .asmdef into a subfolder.","Delete the duplicate assembly-definition file if it was created unintentionally."],"exampleFix":"// before: Assets/MyLib/A.asmdef and Assets/MyLib/B.asmdef\n// after: Assets/MyLib/A.asmdef  and  Assets/MyLib/Sub/B.asmdef","handlingStrategy":"validation","validationCode":"// Same folder-prefix collision check as 705, applied to .asmdef files\nvar byPrefix = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);\nforeach (var f in allAsmdefPaths)\n    (byPrefix[System.IO.Path.GetDirectoryName(f)?.Replace('\\\\','/')] ??= new List<string>()).Add(f);\n\nvar dup = byPrefix.FirstOrDefault(kv => kv.Value.Count > 1);\nif (dup.Value != null)\n    throw new InvalidOperationException($\"Folder '{dup.Key}' has multiple asmdef files: {string.Join(\", \", dup.Value)}\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Place at most one .asmdef per folder.","When splitting code, use subfolders with their own asmdefs rather than multiple asmdefs in one folder.","CI: fail builds where a folder contains more than one assembly-definition file."],"tags":["unity","asmdef","script-compilation","folders","duplicate","config"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}