{"record":{"id":"35e121ca90aa43af","repo":"Unity-Technologies/UnityCsReference","slug":"folder-loadedcustomscriptassemblyreference-pathp","errorCode":null,"errorMessage":"Folder '{loadedCustomScriptAssemblyReference.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":252,"sourceCode":"                    if (contents != null)\n                    {\n                        var jsonContents = contents[i];\n                        loadedCustomScriptAssemblyReference = LoadCustomScriptAssemblyReferenceFromJson(fullPath, jsonContents);\n                    }\n                    else\n                    {\n                        loadedCustomScriptAssemblyReference = LoadCustomScriptAssemblyReferenceFromJsonPath(fullPath);\n                    }\n\n                    if (!m_SkipCustomScriptAssemblyGraphValidation)\n                    {\n                        // Check both asmdef and asmref files.\n                        if (prefixToFilePathLookup.TryGetValue(loadedCustomScriptAssemblyReference.PathPrefix, out var duplicateFilePaths))\n                        {\n                            var filePaths = new List<string> {loadedCustomScriptAssemblyReference.FilePath};\n                            filePaths.AddRange(duplicateFilePaths);\n\n                            throw new AssemblyDefinitionException(\n                                $\"Folder '{loadedCustomScriptAssemblyReference.PathPrefix}' contains multiple assembly definition files\", filePaths.ToArray());\n                        }\n                    }\n\n                    // Convert GUID references to assembly names\n                    if (GUIDReference.IsGUIDReference(loadedCustomScriptAssemblyReference.Reference))\n                    {\n                        // Generate the guid to assembly lookup?\n#pragma warning disable UA2001 // The Banned API Analyzer produces compile errors for any new Linq code. This pre-existing usage has been suppressed, but should be rewritten if possible.\n                        guidsToAssemblies = guidsToAssemblies ?? CustomScriptAssemblies.ToDictionary(x => x.GUID);\n#pragma warning restore UA2001\n\n                        var guid = Utility.FastToLower(GUIDReference.GUIDReferenceToGUID(loadedCustomScriptAssemblyReference.Reference));\n                        if (guidsToAssemblies.TryGetValue(guid, out var foundAssembly))\n                        {\n                            loadedCustomScriptAssemblyReference.Reference = foundAssembly.Name;\n                        }\n                    }","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Scripting/ScriptCompilation/LoadingAssemblyDefinition.cs#L234-L270","documentation":"Thrown during assembly-reference graph loading (LoadingAssemblyDefinition.cs:252) when a loaded asmref's PathPrefix collides with one already registered in prefixToFilePathLookup. PathPrefix is the folder path that 'owns' an assembly definition. Unity requires that a given folder prefix hold at most one assembly-definition file across both .asmdef and .asmref types, so it can deterministically map a script's folder to a single assembly.","triggerScenarios":"Adding an .asmref file into a folder whose prefix already maps to an .asmdef (or another .asmref). Two assembly-definition files resolving to the same folder prefix.","commonSituations":"Placing an asmref next to an existing asmdef to 'extend' it instead of putting it in a subfolder. Copying an asmdef + asmref pair into a folder that already has one.","solutions":["Move the new .asmref (or the duplicate .asmdef) into its own subfolder so its PathPrefix no longer collides.","Delete the redundant assembly-definition file if it was created by mistake.","Confirm the asmref's 'reference' field points at the intended target asmdef elsewhere rather than implying co-location."],"exampleFix":"// before: both Assets/MyLib/A.asmdef and Assets/MyLib/B.asmref exist\n// after: move the asmref into a subfolder\n//   Assets/MyLib/A.asmdef\n//   Assets/MyLib/Editor/B.asmref","handlingStrategy":"validation","validationCode":"// Enforce one assembly-definition file per folder prefix before reimport\nstatic string PrefixOf(string asmdefPath) =>\n    System.IO.Path.GetDirectoryName(asmdefPath)?.Replace('\\\\', '/');\n\nvar byPrefix = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);\nforeach (var f in allAsmdefAndAsmrefPaths)\n    (byPrefix[PrefixOf(f)] ??= new List<string>()).Add(f);\n\nvar collisions = byPrefix.Where(kv => kv.Value.Count > 1).ToList();\nif (collisions.Any())\n    throw new InvalidOperationException(\n        \"Multiple assembly-definition files in folder(s): \" +\n        string.Join(\", \", collisions.Select(c => c.Key)));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep a single .asmdef or .asmref per folder; place additional ones in subfolders.","Before adding an asmref, confirm its target asmdef lives in a different folder.","Add a CI check that fails when two assembly-definition files share a directory."],"tags":["unity","asmdef","asmref","script-compilation","folders","config"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}