{"record":{"id":"5423d5f2b6d9674f","repo":"dotnet/maui","slug":"expected-nameof-visualstategrouplist-but-found","errorCode":null,"errorMessage":"Expected {nameof(VisualStateGroupList)} but found {parents[3]}.","messagePattern":"Expected (.+?) but found (.+?)\\.","errorType":"exception","errorClass":"XamlParseException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/BindablePropertyConverter.cs","lineNumber":143,"sourceCode":"\t\t\t=> type.GetField(fieldName, BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);\n\n\t\tType FindTypeForVisualState(IProvideParentValues parentValueProvider, IXmlLineInfo lineInfo)\n\t\t{\n\t\t\tvar parents = parentValueProvider.ParentObjects.ToList();\n\n\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","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/BindablePropertyConverter.cs#L125-L161","documentation":"XamlParseException raised in FindTypeForVisualState when parents[3] (after the VisualStateGroup was confirmed) is neither a VisualElement (direct visual states) nor a VisualStateGroupList. The only two valid containers for a VisualStateGroup are a VisualStateGroupList (under a Style) or a VisualElement directly; anything else is a structural error.","triggerScenarios":"Placing a VisualStateGroup under a non-VisualElement and non-VisualStateGroupList parent; a malformed Style whose Setters/VisualStateGroups are mis-nested; custom containers used as visual-state hosts.","commonSituations":"Editing a Style's VisualStateManager section and dropping the VisualStateGroupList wrapper; putting visual states on a non-visual element.","solutions":["If the group lives under a Style, wrap it in a VisualStateGroupList.","If it lives directly on an element, ensure that element is a VisualElement.","Match the documented parent chain for the Style vs direct-element cases."],"exampleFix":"<!-- before -->\n<Style><VisualStateGroup> ... </VisualStateGroup></Style>\n\n<!-- after -->\n<Style>\n  <VisualStateManager.VisualStateGroups>\n    <VisualStateGroupList>\n      <VisualStateGroup> ... </VisualStateGroup>\n    </VisualStateGroupList>\n  </VisualStateManager.VisualStateGroups>\n</Style>","handlingStrategy":"validation","validationCode":"// In a Style, wrap VisualStateGroup in a VisualStateGroupList under\n// VisualStateManager.VisualStateGroups.","typeGuard":null,"tryCatchPattern":"try { /* compile */ }\ncatch (XamlParseException ex) when (ex.Message.Contains(\"VisualStateGroupList\"))\n{\n    // prompt author to add the VisualStateGroupList wrapper\n}","preventionTips":["Distinguish the direct-element vs Style cases for visual states.","Use the canonical nesting from the docs."],"tags":["maui","xaml","visualstate","converter","markup-structure"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}