{"record":{"id":"00754a30ea436390","repo":"unoplatform/uno","slug":"there-is-already-a-resource-with-name-name","errorCode":null,"errorMessage":"There is already a resource with name '{name}'","messagePattern":"There is already a resource with name '(.+?)'","errorType":"exception","errorClass":"XamlGenerationException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs","lineNumber":2883,"sourceCode":"\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tusing (TryTernaryForLinkerHint(writer, resource))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tusing (BuildLazyResourceInitializer(writer))\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tBuildChild(writer, null, resource);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\twriter.AppendLineIndented(closingPunctuation);\n\t\t\t\t}\n\n\t\t\t\tif (name != null && !_isTopLevelDictionary)\n\t\t\t\t{\n\t\t\t\t\tif (_namedResources.ContainsKey(name))\n\t\t\t\t\t{\n\t\t\t\t\t\tthrow new XamlGenerationException($\"There is already a resource with name '{name}'\", resource);\n\t\t\t\t\t}\n\t\t\t\t\t_namedResources.Add(name, resource);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tprivate IDisposable TryTernaryForLinkerHint(IIndentedStringBuilder writer, XamlObjectDefinition resource)\n\t\t\t=> TryLinkerHint(\n\t\t\t\tresource,\n\t\t\t\ts => writer.AppendLineIndented($\"{s} ? (\"),\n\t\t\t\t() => writer.AppendLineIndented(\"): null\")\n\t\t\t);\n\n\t\tprivate IDisposable TrySingleLineIfForLinkerHint(IIndentedStringBuilder writer, XamlObjectDefinition resource)\n\t\t\t=> TryLinkerHint(\n\t\t\t\tresource,\n\t\t\t\ts => writer.AppendLineIndented($\"if({s})\"),\n\t\t\t\t() => { }","sourceCodeStart":2865,"sourceCodeEnd":2901,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs#L2865-L2901","documentation":"Thrown in BuildNamedResources when a resource (an entry in a ResourceDictionary or top-level resource) uses an x:Key or x:Name that already exists in the _namedResources map (line 62). The check at line 2881 only applies when _isTopLevelDictionary is false — i.e. inside a resource block within a page/control. Duplicate keys would produce ambiguous generated backing-field names, so generation aborts.","triggerScenarios":"Two resources in the same (non-top-level) ResourceDictionary with the same x:Key; a resource whose x:Name collides with another resource's key; merging inline resources where both define \"MyBrush\".","commonSituations":"Copy-pasting a resource and forgetting to rename its key; splitting a large dictionary and introducing a duplicate; merging dictionaries inline that share keys at the same scope.","solutions":["Search the file (and merged dictionaries at that scope) for the duplicate key and rename one occurrence.","If the duplicate is intentional across separate MergedDictionaries, move them into separate ResourceDictionary files referenced via MergedDictionaries (top-level dictionaries bypass this check).","Use distinct, descriptive keys (e.g. HeaderBrush vs FooterBrush) to avoid accidental collisions."],"exampleFix":"<!-- before -->\n<Page.Resources>\n  <SolidColorBrush x:Key=\"Accent\" Color=\"Red\"/>\n  <SolidColorBrush x:Key=\"Accent\" Color=\"Blue\"/>\n</Page.Resources>\n\n<!-- after -->\n<Page.Resources>\n  <SolidColorBrush x:Key=\"AccentPrimary\" Color=\"Red\"/>\n  <SolidColorBrush x:Key=\"AccentSecondary\" Color=\"Blue\"/>\n</Page.Resources>","handlingStrategy":"validation","validationCode":"# Detect duplicate x:Key within the same ResourceDictionary block\nGet-ChildItem -Recurse -Filter *.xaml | ForEach-Object {\n  $text = Get-Content $_.FullName -Raw\n  $keys = [regex]::Matches($text, 'x:Key=\"([^\"]+)\"') | ForEach-Object { $_.Groups[1].Value }\n  $dup = $keys | Group-Object | Where-Object { $_.Count -gt 1 }\n  $dup | ForEach-Object { Write-Warning \"$($_.Name): duplicate x:Key in $($_.Group[0])\" }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use descriptive, unique resource keys scoped by feature (e.g. HeaderAccentBrush).","Move shared resources into top-level ResourceDictionary files (MergedDictionaries) where keys are namespaced by file.","Run the duplicate-key lint in CI."],"tags":["xaml","resource-dictionary","duplicate-key","build"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}