aspnetboilerplate/aspnetboilerplate · error · AbpException
A dictionary can not contain same key twice. There are some…
Error message
A dictionary can not contain same key twice. There are some duplicated names:
What it means
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.
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
Example fix
// before <text name="Welcome" value="Welcome" /> <text name="Welcome" value="Hello!" /> // after <text name="Welcome" value="Welcome" />
Defensive patterns
Strategy: validation
Validate before calling
var doc = new XmlDocument(); doc.Load(xmlPath);
var dupes = doc.SelectNodes("//text/@name").Cast<XmlAttribute>()
.GroupBy(a => a.Value).Where(g => g.Count() > 1).Select(g => g.Key).ToList();
if (dupes.Any()) throw new Exception($"{xmlPath}: duplicate keys: {string.Join(", ", dupes)}"); Try / catch
try { var dict = XmlLocalizationDictionary.BuildFomFile(xmlPath); }
catch (AbpException ex) when (ex.Message.StartsWith("A dictionary can not contain same key twice"))
{
_logger.LogError(ex, "Duplicate keys in {File}: {Keys}", xmlPath, ex.Message);
throw;
} Prevention
- 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
When it happens
Trigger: Loading a localization XML where two <text> nodes share a name, e.g. <text name="Welcome" .../> appears twice, during source initialization.
Common situations: Merging translation files (e.g. two contributors both added 'Welcome'); copy-pasting blocks between language files; automated merge tools concatenating XML without dedup.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- A dictionary can not contain same key twice. There are some…
- A Localization Xml must include localizationDictionary as…
- culture is not defined in language XML file!
- Invalid localization file format!
- name attribute of a text is empty in given xml string.
AI-assisted analysis of aspnetboilerplate/aspnetboilerplate@2323c13a15 (2026-09-08).
Data as JSON: /api/errors/e7930cce9a35793c.
Report an issue: GitHub.
Appendix: source
Thrown at src/Abp/Localization/Dictionaries/Xml/XmlLocalizationDictionary.cs:93
{
var name = node.GetAttributeValueOrNull("name");
if (string.IsNullOrEmpty(name))
{
throw new AbpException("name attribute of a text is empty in given xml string.");
}
if (dictionary.Contains(name))
{
dublicateNames.Add(name);
}
dictionary[name] = (node.GetAttributeValueOrNull("value") ?? node.InnerText).NormalizeLineEndings();
}
}
if (dublicateNames.Count > 0)
{
throw new AbpException("A dictionary can not contain same key twice. There are some duplicated names: " + dublicateNames.JoinAsString(", "));
}
return dictionary;
}
}
}
View on GitHub (pinned to 2323c13a15)