{"record":{"id":"32c48abfb75a6668","repo":"dotnet/maui","slug":"expected-nameof-setter-but-found-parents-4","errorCode":null,"errorMessage":"Expected {nameof(Setter)} but found {parents[4]}.","messagePattern":"Expected (.+?) but found (.+?)\\.","errorType":"exception","errorClass":"XamlParseException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/BindablePropertyConverter.cs","lineNumber":149,"sourceCode":"\t\t\t// Skip 0; we would not be making this check if TargetObject were not a Setter\n\t\t\t// Skip 1; we would not be making this check if the immediate parent were not a VisualState\n\n\t\t\t// VisualStates must be in a VisualStateGroup\n\t\t\tif (parents[2] is not VisualStateGroup)\n\t\t\t\tthrow new XamlParseException($\"Expected {nameof(VisualStateGroup)} but found {parents[2]}.\", lineInfo);\n\n\t\t\t// Are these Visual States directly on a VisualElement?\n\t\t\tif (parents[3] is VisualElement vsTarget)\n\t\t\t\treturn vsTarget.GetType();\n\n\t\t\tif (parents[3] is not VisualStateGroupList)\n\t\t\t\tthrow new XamlParseException($\"Expected {nameof(VisualStateGroupList)} but found {parents[3]}.\", lineInfo);\n\n\t\t\tif (parents[4] is VisualElement veTarget)\n\t\t\t\treturn veTarget.GetType();\n\n\t\t\tif (parents[4] is not Setter)\n\t\t\t\tthrow new XamlParseException($\"Expected {nameof(Setter)} but found {parents[4]}.\", lineInfo);\n\n\t\t\tif (parents[5] is TriggerBase trigger)\n\t\t\t\treturn trigger.TargetType;\n\n\t\t\t// These must be part of a Style; verify that \n\t\t\tif (parents[5] is Style style)\n\t\t\t\treturn style.TargetType;\n\n\t\t\tthrow new XamlParseException($\"Unable to find a TragetType for the Bindable Property. Try prefixing it with the TargetType.\", lineInfo);\n\n\t\t}\n\n\t\tpublic override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)\n\t\t{\n\t\t\tif (value is not BindableProperty bp)\n\t\t\t\tthrow new NotSupportedException();\n\t\t\treturn $\"{bp.DeclaringType.Name}.{bp.PropertyName}\";\n\t\t}","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/BindablePropertyConverter.cs#L131-L167","documentation":"XamlParseException raised in FindTypeForVisualState when, in the Style-attached visual-state path, parents[4] is not a Setter. After confirming VisualStateGroupList at parents[3], the converter expects the value context to ultimately be rooted in a Setter; finding something else means the Setter.Property resolution cannot infer the target type from the chain.","triggerScenarios":"A VisualState nested in a Style's VisualStateGroupList where the immediate parent of the property reference is not a Setter; malformed Setters collection that places a Setter in the wrong slot; a Setter whose Property is being resolved outside its expected position.","commonSituations":"Editing Style/Setters XAML by hand and displacing a Setter; tool output that interleaves Setters with other nodes incorrectly.","solutions":["Ensure each Setter sits directly in the Setters collection and the Property attribute is on the Setter.","Re-create the VisualState/Setter markup from a known-good template.","Validate the Style/Setters/VisualStateManager nesting against the docs."],"exampleFix":"<!-- before: Setter placed where converter expects a different node -->\n<VisualStateGroupList>\n  <VisualStateGroup>\n    <VisualState>\n      <VisualState.Setters>\n        <!-- mis-nested nodes -->\n      </VisualState.Setters>\n    </VisualState>\n  </VisualStateGroup>\n</VisualStateGroupList>\n\n<!-- after -->\n<VisualStateGroupList>\n  <VisualStateGroup>\n    <VisualState x:Name=\"N\">\n      <VisualState.Setters>\n        <Setter Property=\"VisualElement.BackgroundColor\" Value=\"Red\" />\n      </VisualState.Setters>\n    </VisualState>\n  </VisualStateGroup>\n</VisualStateGroupList>","handlingStrategy":"validation","validationCode":"// Keep Setter as the direct parent of the resolved Property attribute within\n// VisualState.Setters.","typeGuard":null,"tryCatchPattern":"try { /* compile */ }\ncatch (XamlParseException ex) when (ex.Message.Contains(\"Setter\"))\n{\n    // verify Setter placement in the visual-state chain\n}","preventionTips":["Place Setters inside VisualState.Setters only.","Avoid interleaving non-Setter nodes in the chain."],"tags":["maui","xaml","visualstate","converter","setter","markup-structure"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}