{"record":{"id":"9709e7e306acc201","repo":"unoplatform/uno","slug":"each-dictionary-entry-must-have-a-key","errorCode":null,"errorMessage":"Each dictionary entry must have a 'Key'","messagePattern":"Each dictionary entry must have a 'Key'","errorType":"exception","errorClass":"XamlGenerationException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs","lineNumber":3052,"sourceCode":"\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\twriter.AppendLineInvariantIndented(\"// {0}\", propertyName);\n\t\t\t}\n\n\t\t\tfor (int i = 0; i < dictionaries.Objects.Count; i++)\n\t\t\t{\n\t\t\t\tvar dictObject = dictionaries.Objects[i];\n\t\t\t\tvar source = dictObject.Members.FirstOrDefault(m => m.Member.Name == \"Source\");\n\t\t\t\tif (source != null && dictObject.Members.Any(m => m.Member.Name == \"_UnknownContent\"))\n\t\t\t\t{\n\t\t\t\t\tthrow new XamlGenerationException(\"Local values are not allowed in resource dictionary with Source set\", dictObject);\n\t\t\t\t}\n\n\t\t\t\tvar key = GetDictionaryResourceKey(dictObject);\n\t\t\t\tif (isDict && key == null)\n\t\t\t\t{\n\t\t\t\t\tthrow new XamlGenerationException(\"Each dictionary entry must have a 'Key'\", dictObject);\n\t\t\t\t}\n\n\t\t\t\tvar former = _themeDictionaryCurrentlyBuilding; //Will 99% of the time be null.\n\t\t\t\tif (isDict)\n\t\t\t\t{\n\t\t\t\t\t_themeDictionaryCurrentlyBuilding = key;\n\t\t\t\t}\n\n\t\t\t\tif (!isSetExtensionMethod)\n\t\t\t\t{\n\t\t\t\t\tif (!isInInitializer && !isDict)\n\t\t\t\t\t{\n\t\t\t\t\t\twriter.AppendLineInvariantIndented(\"{0}.{1}.Add(\", dictIdentifier, propertyName);\n\t\t\t\t\t}\n\t\t\t\t\telse if (!isInInitializer && isDict)\n\t\t\t\t\t{\n\t\t\t\t\t\twriter.AppendLineInvariantIndented(\"{0}.{1}[\\\"{2}\\\"] = \", dictIdentifier, propertyName, key);\n\t\t\t\t\t}","sourceCodeStart":3034,"sourceCodeEnd":3070,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs#L3034-L3070","documentation":"Thrown in the same dictionary loop when isDict is true but GetDictionaryResourceKey returns null for an entry — i.e. a dictionary entry has no x:Key (and no x:Name fallback that the key resolver accepts). Every entry in a keyed ResourceDictionary requires a key so the generator can emit it into the generated dictionary initializer.","triggerScenarios":"An element inside a <ResourceDictionary> (not a MergedDictionaries child) lacking x:Key; a resource relying on an implicit key (by TargetType in a Style) which Uno does not infer in this context.","commonSituations":"Porting WPF styles that use implicit Style keys (Style keyed by its TargetType) into a context where the generator requires an explicit key; forgetting x:Key on a brush/style added in haste.","solutions":["Add x:Key=\"someKey\" to every entry directly inside a ResourceDictionary.","For a Style, add x:Key even if TargetType is set, unless the style is intentionally implicit (in which case ensure it is in the right implicit-style location).","If the entry is meant to be merged from elsewhere, move it under MergedDictionaries with a Source."],"exampleFix":"<!-- before -->\n<ResourceDictionary>\n  <SolidColorBrush Color=\"Red\"/>\n</ResourceDictionary>\n\n<!-- after -->\n<ResourceDictionary>\n  <SolidColorBrush x:Key=\"RedBrush\" Color=\"Red\"/>\n</ResourceDictionary>","handlingStrategy":"validation","validationCode":"# Flag elements inside <ResourceDictionary> (not MergedDictionaries) lacking x:Key\nGet-ChildItem -Recurse -Filter *.xaml | ForEach-Object {\n  $x = [xml](Get-Content $_.FullName)\n  $x.SelectNodes('//*[local-name()=\"ResourceDictionary\"]/*') | Where-Object {\n    $_.LocalName -ne 'ResourceDictionary.MergedDictionaries' -and -not $_.HasAttribute('Key','http://schemas.microsoft.com/winfx/2006/xaml')\n  } | ForEach-Object { Write-Warning \"Entry $($_.LocalName) missing x:Key\" }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Give every resource an explicit x:Key even if it has a TargetType (Uno does not infer implicit keys in all contexts).","For implicit Styles, ensure they are placed where implicit-key semantics are supported, or add x:Key."],"tags":["xaml","resource-dictionary","missing-key","build"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}