{"record":{"id":"23e1840b4cd02e75","repo":"AvaloniaUI/Avalonia","slug":"controltheme-has-no-targettype","errorCode":null,"errorMessage":"ControlTheme has no TargetType.","messagePattern":"ControlTheme has no TargetType\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Styling/ControlTheme.cs","lineNumber":48,"sourceCode":"        /// Gets or sets a control theme that is the basis of the current theme.\n        /// </summary>\n        public ControlTheme? BasedOn { get; set; }\n\n        public override string ToString() => TargetType?.Name ?? \"ControlTheme\";\n\n        internal override void SetParent(StyleBase? parent)\n        {\n            throw new InvalidOperationException(\"ControlThemes cannot be added as a nested style.\");\n        }\n\n        internal SelectorMatchResult TryAttach(StyledElement target, FrameType type)\n        {\n            Debug.Assert(type is FrameType.Theme or FrameType.TemplatedParentTheme);\n\n            _ = target ?? throw new ArgumentNullException(nameof(target));\n\n            if (TargetType is null)\n                throw new InvalidOperationException(\"ControlTheme has no TargetType.\");\n\n            using var activity = Diagnostic.AttachingStyle()?\n                .AddTag(Diagnostic.Tags.Style, this);\n            \n            if (HasSettersOrAnimations && TargetType.IsAssignableFrom(target.StyleKey))\n            {\n                Attach(target, null, type, true);\n                activity?.AddTag(Diagnostic.Tags.SelectorResult, SelectorMatchResult.AlwaysThisType);\n\n                return SelectorMatchResult.AlwaysThisType;\n            }\n\n            activity?.AddTag(Diagnostic.Tags.SelectorResult, SelectorMatchResult.NeverThisType);\n            return SelectorMatchResult.NeverThisType;\n        }\n    }\n}\n","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Styling/ControlTheme.cs#L30-L66","documentation":"Error \"ControlTheme has no TargetType.\" thrown in AvaloniaUI/Avalonia.","triggerScenarios":"Raised when a ControlTheme is evaluated without its TargetType being set. Defend by always setting TargetType on a ControlTheme before it is used and validating themes at load time.","commonSituations":"See trigger scenarios.","solutions":["Set the ControlTheme's TargetType property to the control type the theme applies to.","Verify the x:Key/TargetType is declared in XAML: <ControlTheme TargetType=\"Button\">."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}