{"record":{"id":"79f00c43daccf9b5","repo":"unoplatform/uno","slug":"membername-is-not-defined-on-xamlobjectdefin","errorCode":null,"errorMessage":"'{memberName}' is not defined on '{xamlObjectDefinition.Type.Name}'","messagePattern":"'(.+?)' is not defined on '(.+?)'","errorType":"exception","errorClass":"XamlGenerationException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs","lineNumber":2333,"sourceCode":"\t\t{\n\t\t\tforeach (var member in xamlObjectDefinition.Members)\n\t\t\t{\n\t\t\t\tif (member.Member.Name == memberName && member.Member.PreferredXamlNamespace == ns)\n\t\t\t\t{\n\t\t\t\t\treturn member;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn null;\n\t\t}\n\n\t\tprivate XamlMemberDefinition GetMember(XamlObjectDefinition xamlObjectDefinition, string memberName)\n\t\t{\n\t\t\tvar member = FindMember(xamlObjectDefinition, memberName);\n\n\t\t\tif (member == null)\n\t\t\t{\n\t\t\t\tthrow new XamlGenerationException($\"'{memberName}' is not defined on '{xamlObjectDefinition.Type.Name}'\", xamlObjectDefinition);\n\t\t\t}\n\n\t\t\treturn member;\n\t\t}\n\n\t\tprivate XClassName GetClassName(XamlObjectDefinition control)\n\t\t{\n\t\t\tvar classMember = FindClassName(control);\n\n\t\t\tif (classMember == null)\n\t\t\t{\n\t\t\t\tthrow new XamlGenerationException(\"Unable to find class name for toplevel control\", control);\n\t\t\t}\n\n\t\t\treturn classMember;\n\t\t}\n\n\t\tprivate XClassName? FindClassName(XamlObjectDefinition control)","sourceCodeStart":2315,"sourceCodeEnd":2351,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs#L2315-L2351","documentation":"Thrown by GetMember() when a required XAML member (attribute or child element) is not present on an object. GetMember is the non-null-throwing counterpart to FindMember; it is only called when the generator considers the member mandatory. It fires in three concrete call sites: a ResourceDictionary entry missing x:Key (XamlFileGenerator.cs:2527), a Style missing TargetType (line 6491), and a Setter that has Value but neither Property nor Target inside a styled target (line 6074). The error is an XamlGenerationException carrying the source location of the offending XAML node.","triggerScenarios":"Authoring a <Style> element without a TargetType attribute; placing an entry inside a <ResourceDictionary> (or any IDictionary-backed collection) without an x:Key; writing a <Setter Value=\"...\"> with no matching Property or Target inside a Style whose TargetType is set (the GetMember(member.Owner, \"Target\") call at line 6074 throws rather than falling through).","commonSituations":"Porting XAML from WPF/SL where keys were sometimes inferred; copy-paste of a Setter that drops the Property attribute; using a merged dictionary style that relies on implicit keys (Uno requires explicit keys); refactoring a Style and forgetting TargetType.","solutions":["Add the missing attribute the message names: for a dictionary entry add x:Key=\"myKey\"; for a Style add TargetType=\"Button\"; for a Setter add Property=\"Width\".","If the error points at a Setter/Target (line 6074 path), give the Setter either a Property=\"...\" or Target=\"...\" so the generator can resolve the property type.","Open the file/line the exception reports (it carries IXamlLocation) and confirm the named member is actually spelled correctly (case-sensitive, no xmlns prefix mismatch).","Run dotnet xstyler on the SamplesApp XAML to normalize structure, then rebuild."],"exampleFix":"<!-- before -->\n<Style>\n  <Setter Value=\"20\"/>\n</Style>\n\n<!-- after -->\n<Style TargetType=\"Button\">\n  <Setter Property=\"Width\" Value=\"20\"/>\n</Style>","handlingStrategy":"validation","validationCode":"// Pre-build XAML lint (PowerShell or an MSBuild target) before invoking the generator:\n# Ensure every Style has TargetType and every ResourceDictionary entry has x:Key\nSelect-String -Path 'src\\**\\*.xaml' -Pattern '<Style(?![^>]*TargetType)' |\n  ForEach-Object { Write-Warning \"$($_.Filename):$($_.LineNumber): <Style> missing TargetType\" }\n# Check dictionary entries without x:Key (heuristic):\nSelect-String -Path 'src\\**\\*.xaml' -Pattern '<(SolidColorBrush|Style|DataTemplate)(?![^>]*x:Key)' |\n  ForEach-Object { Write-Warning \"$($_.Filename):$($_.LineNumber): possible missing x:Key\" }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pair <Style> with TargetType and <Setter> with Property at authoring time.","Give every ResourceDictionary entry an explicit x:Key even if a TargetType is present.","Run an XAML linter (dotnet xstyler -p in check mode) in CI to catch structural omissions before the generator runs."],"tags":["xaml","source-generator","style","resource-dictionary","build"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}