{"record":{"id":"31c919274bc470c7","repo":"AvaloniaUI/Avalonia","slug":"invalid-selector-template-selector-must-be-follow","errorCode":null,"errorMessage":"Invalid selector: Template selector must be followed by control selector.","messagePattern":"Invalid selector: Template selector must be followed by control selector\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Styling/Style.cs","lineNumber":96,"sourceCode":"                        SelectorMatch.NeverThisInstance);\n\n                activity?.AddTag(Diagnostic.Tags.SelectorResult, match.Result);\n\n                if (match.IsMatch)\n                {\n                    Attach(target, match.Activator, type, Selector is not OrSelector);\n                }\n\n                result = match.Result;\n            }\n\n            return result;\n        }\n\n        private static Selector? ValidateSelector(Selector? selector)\n        {\n            if (selector is TemplateSelector)\n                throw new InvalidOperationException(\n                    \"Invalid selector: Template selector must be followed by control selector.\");\n            return selector;\n        }\n    }\n}\n","sourceCodeStart":78,"sourceCodeEnd":102,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Styling/Style.cs#L78-L102","documentation":"Thrown by Style.ValidateSelector (invoked from the Selector setter) when the assigned selector is a bare TemplateSelector with nothing following it. The Template selector (`/template/`) only makes sense when followed by a selector addressing a part inside the template; a lone TemplateSelector has no target part and is rejected at assignment time.","triggerScenarios":"Assigning `s.Template()` alone as a Style's Selector (no subsequent OfType/Class/etc.), or AXAML `Selector=\"... /template/\"` with nothing after the template token.","commonSituations":"Truncated selector after refactoring; AXAML where the post-template part was deleted; programmatic selector building that stops at Template().","solutions":["Follow the Template selector with a part selector, e.g. `s.OfType<Button>().Template().OfType<ContentPresenter>()`.","In AXAML, write `Button /template/ ContentPresenter` rather than just `Button /template/`.","If you did not intend template traversal, remove the Template selector."],"exampleFix":"// before\nnew Style(s => s.OfType<Button>().Template())\n\n// after\nnew Style(s => s.OfType<Button>().Template().OfType<ContentPresenter>())","handlingStrategy":"validation","validationCode":"// Reject a bare TemplateSelector before assigning to Style.Selector.\nif (selector is TemplateSelector)\n    throw new InvalidOperationException(\"Template selector must be followed by a part selector.\");","typeGuard":"static bool IsCompleteTemplateChain(Selector? s) => s is not TemplateSelector;","tryCatchPattern":null,"preventionTips":["Always follow Template() with a part selector (OfType/Class/etc.).","In AXAML, write `Control /template/ Part` not just `Control /template/`.","Build a helper that asserts the chain is non-trivial after a template step."],"tags":["avalonia","styling","template-selector","selector","validation"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}