{"record":{"id":"c2fa9d8d1ba5d4d1","repo":"Unity-Technologies/UnityCsReference","slug":"assembly-has-duplicate-references-duplicaterefss","errorCode":null,"errorMessage":"Assembly has duplicate references: {duplicateRefsString}","messagePattern":"Assembly has duplicate references: (.+?)","errorType":"exception","errorClass":"AssemblyDefinitionException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Scripting/ScriptCompilation/LoadingAssemblyDefinition.cs","lineNumber":173,"sourceCode":"            {\n                try\n                {\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                    var references = loadedCustomScriptAssembly.References.Where(r => !string.IsNullOrEmpty(r))\n#pragma warning restore UA2001\n                        .ToArray();\n\n                    if (references.Length == references.DistinctCount())\n                    {\n                        continue;\n                    }\n\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                    var duplicateRefs = references.GroupBy(r => r).SelectMany(g => g.Skip(1)).ToArray();\n#pragma warning restore UA2001\n                    var duplicateRefsString = string.Join(\",\", duplicateRefs);\n\n                    throw new AssemblyDefinitionException(\n                        $\"Assembly has duplicate references: {duplicateRefsString}\",\n                        loadedCustomScriptAssembly.FilePath);\n                }\n                catch (Exception e)\n                {\n                    m_CompilationSetupErrorsTracker.SetCompilationSetupErrors(CompilationSetupErrors.LoadError);\n                    exceptions.Add(e);\n                }\n            }\n        }\n\n        static void ConvertGUIDReferencesToAssemblyNames(List<CustomScriptAssembly> assemblies, Dictionary<string, CustomScriptAssembly> guidsToAssemblies)\n        {\n            foreach (var assembly in assemblies)\n            {\n                for (int i = 0; i < assembly.References.Length; ++i)\n                {\n                    var reference = assembly.References[i];","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Scripting/ScriptCompilation/LoadingAssemblyDefinition.cs#L155-L191","documentation":"Thrown while validating a loaded assembly's references (LoadingAssemblyDefinition.cs:173) when the references array, after GUID-to-name conversion and other processing, contains duplicates. The message lists the duplicated reference strings. Duplicate references are rejected because they create ambiguity in the dependency graph and can double-count version/define contributions.","triggerScenarios":"An asmdef whose references list the same assembly twice, or the same target referenced once by GUID and once by assembly name (both resolve to the same string after conversion). An asmref that adds a reference already implied by another reference.","commonSituations":"Hand-editing references and duplicating a line. Migrating from GUID references to name references and forgetting to remove the old GUID entry. Copying an asmdef and merging reference lists.","solutions":["Open the asmdef and remove the duplicate reference entry so each target appears exactly once.","If using GUID references, ensure the same assembly is not also referenced by name elsewhere in the same file."],"exampleFix":"// before (.asmdef)\n\"references\": [\"MyLib\", \"GUID:abc123...\", \"MyLib\"]\n// after\n\"references\": [\"MyLib\", \"GUID:abc123...\"]","handlingStrategy":"validation","validationCode":"// De-duplicate references before saving an asmdef (after GUID->name resolution)\nvar seen = new HashSet<string>(StringComparer.Ordinal);\nvar deduped = new List<string>();\nforeach (var r in data.references ?? Array.Empty<string>())\n{\n    var key = r; // normalize GUID refs if needed before this step\n    if (seen.Add(key)) deduped.Add(r);\n}\nif (deduped.Count != (data.references?.Length ?? 0))\n    data.references = deduped.ToArray(); // duplicates removed","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Maintain references through the Inspector so duplicates cannot be introduced by hand.","When migrating GUID references to names, remove the original GUID entries in the same edit.","Run a de-duplication pass over the references array before serializing."],"tags":["unity","asmdef","script-compilation","references","config"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}