{"record":{"id":"e7930cce9a35793c","repo":"aspnetboilerplate/aspnetboilerplate","slug":"a-dictionary-can-not-contain-same-key-twice-there-e7930c","errorCode":null,"errorMessage":"A dictionary can not contain same key twice. There are some duplicated names: ","messagePattern":"A dictionary can not contain same key twice\\. There are some duplicated names: ","errorType":"exception","errorClass":"AbpException","httpStatus":null,"severity":"error","filePath":"src/Abp/Localization/Dictionaries/Xml/XmlLocalizationDictionary.cs","lineNumber":93,"sourceCode":"                {\n                    var name = node.GetAttributeValueOrNull(\"name\");\n                    if (string.IsNullOrEmpty(name))\n                    {\n                        throw new AbpException(\"name attribute of a text is empty in given xml string.\");\n                    }\n\n                    if (dictionary.Contains(name))\n                    {\n                        dublicateNames.Add(name);\n                    }\n\n                    dictionary[name] = (node.GetAttributeValueOrNull(\"value\") ?? node.InnerText).NormalizeLineEndings();\n                }\n            }\n\n            if (dublicateNames.Count > 0)\n            {\n                throw new AbpException(\"A dictionary can not contain same key twice. There are some duplicated names: \" + dublicateNames.JoinAsString(\", \"));\n            }\n\n            return dictionary;\n        }\n    }\n}\n","sourceCodeStart":75,"sourceCodeEnd":100,"githubUrl":"https://github.com/aspnetboilerplate/aspnetboilerplate/blob/2323c13a152aa0ebfb37af3830f687d7f5b53795/src/Abp/Localization/Dictionaries/Xml/XmlLocalizationDictionary.cs#L75-L100","documentation":"Thrown by Abp.XmlLocalizationDictionary.BuildFomXmlString when the same 'name' key appears on two or more <text> nodes in a localization XML file. ABP collects all duplicate names and throws once at the end, listing them comma-separated, because a dictionary cannot hold the same key twice.","triggerScenarios":"Loading a localization XML where two <text> nodes share a name, e.g. <text name=\"Welcome\" .../> appears twice, during source initialization.","commonSituations":"Merging translation files (e.g. two contributors both added 'Welcome'); copy-pasting blocks between language files; automated merge tools concatenating XML without dedup.","solutions":["Remove or rename duplicate <text> entries so each name appears once per file; the exception message lists the duplicated names","Search the failing XML for the listed name(s) and delete all but one occurrence","If duplicates come from merges, re-run the merge and dedupe keys","Consider storing extended texts per source so one file overriding another does not produce duplicate keys in the same file"],"exampleFix":"// before\n<text name=\"Welcome\" value=\"Welcome\" />\n<text name=\"Welcome\" value=\"Hello!\" />\n// after\n<text name=\"Welcome\" value=\"Welcome\" />","handlingStrategy":"validation","validationCode":"var doc = new XmlDocument(); doc.Load(xmlPath);\nvar dupes = doc.SelectNodes(\"//text/@name\").Cast<XmlAttribute>()\n    .GroupBy(a => a.Value).Where(g => g.Count() > 1).Select(g => g.Key).ToList();\nif (dupes.Any()) throw new Exception($\"{xmlPath}: duplicate keys: {string.Join(\", \", dupes)}\");","typeGuard":null,"tryCatchPattern":"try { var dict = XmlLocalizationDictionary.BuildFomFile(xmlPath); }\ncatch (AbpException ex) when (ex.Message.StartsWith(\"A dictionary can not contain same key twice\"))\n{\n    _logger.LogError(ex, \"Duplicate keys in {File}: {Keys}\", xmlPath, ex.Message);\n    throw;\n}","preventionTips":["Deduplicate keys after every merge of translation files","Run a CI check that builds all language XMLs and fails on duplicates","Use distinct names for override entries instead of duplicating within one file"],"tags":["localization","xml","duplicate-keys","abp"],"backgroundTag":"schema-validation-failed","analyzedSha":"2323c13a152aa0ebfb37af3830f687d7f5b53795","analyzedAt":"2026-09-08T08:00:50.638Z","contentChangedAt":"2026-09-08T08:00:50.638Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}