{"record":{"id":"7725c6837ae8f56a","repo":"unoplatform/uno","slug":"dictionary-item-resource-type-name-has-duplic","errorCode":null,"errorMessage":"Dictionary item '{resource.Type?.Name}' has duplicate key '{key}' {(theme != null ? $\"in theme '{theme}'\" : \"\")}","messagePattern":"Dictionary item '(.+?)' has duplicate key '(.+?)' (.+?)'\" : \"\"\\)\\}","errorType":"exception","errorClass":"XamlGenerationException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs","lineNumber":1640,"sourceCode":"\t\t\tvar resources = (resourcesRoot?.Objects).Safe();\n\t\t\tvar initializers = new Dictionary<XamlObjectDefinition, string>();\n\n\t\t\t// Pre-populate initializer names (though this is probably no longer necessary...?)\n\t\t\tvar index = _dictionaryPropertyIndex;\n\t\t\tforeach (var resource in resources)\n\t\t\t{\n\t\t\t\tvar key = GetDictionaryResourceKey(resource);\n\n\t\t\t\tif (key == null || IsNativeStyle(resource))\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tindex++;\n\t\t\t\tvar propertyName = GetInitializerNameForResourceKey(index);\n\t\t\t\tif (_topLevelQualifiedKeys.ContainsKey((theme, key)))\n\t\t\t\t{\n\t\t\t\t\tthrow new XamlGenerationException($\"Dictionary item '{resource.Type?.Name}' has duplicate key '{key}' {(theme != null ? $\"in theme '{theme}'\" : \"\")}\", resource);\n\t\t\t\t}\n\t\t\t\tvar isStaticResourceAlias = resource.Type.Name == \"StaticResource\";\n\t\t\t\tif (!isStaticResourceAlias)\n\t\t\t\t{\n\t\t\t\t\t_topLevelQualifiedKeys[(theme, key)] = propertyName;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tvar former = _themeDictionaryCurrentlyBuilding; //Will 99% of the time be null. (Mainly this is half-heartedly trying to support funky usage of recursive merged dictionaries.)\n\t\t\t_themeDictionaryCurrentlyBuilding = theme;\n\t\t\tforeach (var resource in resources)\n\t\t\t{\n\t\t\t\tvar key = GetDictionaryResourceKey(resource);\n\n\t\t\t\tif (key == null || IsNativeStyle(resource))\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}","sourceCodeStart":1622,"sourceCodeEnd":1658,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs#L1622-L1658","documentation":"Thrown by the resource dictionary key-registration logic when two resources share the same x:Key within the same theme scope. The exception message includes the resource type name, the duplicate key, and the theme (if applicable). This is a XamlGenerationException, meaning it includes location info.","triggerScenarios":"Two or more resource entries in the same ResourceDictionary (or across merged dictionaries at the top level) define the same x:Key — e.g. two <x:String x:Key=\"MyKey\"> entries, or a themed resource that collides across Light/Dark themes incorrectly.","commonSituations":"Copy-paste of a resource without changing the key; merging multiple resource dictionaries that define the same key; theme resources that inadvertently share a key when they should be in separate theme scopes; refactoring that left orphaned duplicate entries.","solutions":["Search the XAML for the duplicate key reported in the error and remove or rename one of the entries.","If using merged dictionaries, check all merged sources for conflicting keys.","If the duplicate is intentional across themes, ensure each is in the correct ThemeDictionaries scope.","Use a unique x:Key for each resource."],"exampleFix":"<!-- before -->\n<ResourceDictionary>\n  <x:String x:Key=\"MyBrush\">Red</x:String>\n  <x:String x:Key=\"MyBrush\">Blue</x:String>\n</ResourceDictionary>\n<!-- after -->\n<ResourceDictionary>\n  <x:String x:Key=\"MyBrush\">Red</x:String>\n  <x:String x:Key=\"MyBrushAlt\">Blue</x:String>\n</ResourceDictionary>","handlingStrategy":"validation","validationCode":"// Scan for duplicate x:Key values before building:\n// In a pre-build linting step, parse XAML resource dictionaries and collect keys:\n//   var keys = new HashSet<string>();\n//   foreach (var key in allResourceKeys) {\n//       if (!keys.Add(key)) Console.WriteLine($\"Duplicate key: {key}\");\n//   }\n<!-- In XAML, search: grep 'x:Key=\"' across all merged dictionaries for collisions -->","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use unique x:Key values for every resource entry.","When merging dictionaries, check for key conflicts across all sources.","Keep themed resources inside their respective ThemeDictionaries scope."],"tags":["resource-dictionary","xaml","source-generator","duplicate-key"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}