{"record":{"id":"0ff1e01b86ae714c","repo":"AvaloniaUI/Avalonia","slug":"not-selector-must-have-a-selector-argument","errorCode":null,"errorMessage":"Not selector must have a selector argument.","messagePattern":"Not selector must have a selector argument\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Styling/NotSelector.cs","lineNumber":25,"sourceCode":"{\n    /// <summary>\n    /// The `:not()` style selector.\n    /// </summary>\n    internal class NotSelector : Selector\n    {\n        private readonly Selector? _previous;\n        private readonly Selector _argument;\n        private string? _selectorString;\n\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"NotSelector\"/> class.\n        /// </summary>\n        /// <param name=\"previous\">The previous selector.</param>\n        /// <param name=\"argument\">The selector to be not-ed.</param>\n        public NotSelector(Selector? previous, Selector argument)\n        {\n            _previous = previous;\n            _argument = argument ?? throw new InvalidOperationException(\"Not selector must have a selector argument.\");\n        }\n\n        /// <inheritdoc/>\n        internal override bool InTemplate => _argument.InTemplate;\n\n        /// <inheritdoc/>\n        internal override bool IsCombinator => false;\n\n        /// <inheritdoc/>\n        internal override Type? TargetType => _previous?.TargetType;\n\n        /// <inheritdoc/>\n        public override string ToString(Style? owner)\n        {\n            if (_selectorString == null)\n            {\n                _selectorString = $\"{_previous?.ToString(owner, true)}:not({_argument})\";\n            }","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Styling/NotSelector.cs#L7-L43","documentation":"Thrown by the NotSelector constructor when its `argument` parameter is null. The `:not()` selector requires a valid inner selector to invert. The public `Selectors.Not()` overloads pass through the argument, so a null arises only when a Func<Selector?,Selector> returns null or a null Selector is passed directly.","triggerScenarios":"Calling `selector.Not(s => null)` where the lambda returns null, or `new NotSelector(prev, null)` / `Selectors.Not(prev, (Selector)null)`. Also possible via a malformed AXAML `:not()` with empty content.","commonSituations":"Writing a Not() factory lambda that conditionally returns null; building selectors reflectively or from data where the inner selector is missing; AXAML `Selector=\"...:not()\"` with nothing inside the parentheses.","solutions":["Ensure the argument to Not() is a non-null selector, e.g. `s.Not(x => x.Class(\"disabled\"))`.","If building from data, guard against null before calling Not().","In AXAML, make sure `:not(...)` contains a real selector expression."],"exampleFix":"// before\nselector = selector.Not(_ => GetSelectorMaybeNull()); // may return null\n\n// after\nvar inner = GetSelectorMaybeNull();\nif (inner is not null)\n    selector = selector.Not(inner);","handlingStrategy":"validation","validationCode":"Selector? inner = factory(null);\nif (inner is null) throw new InvalidOperationException(\"Not() requires a non-null inner selector.\");\nselector = selector.Not(inner);","typeGuard":"static bool IsValidNotArgument(Selector? arg) => arg is not null;","tryCatchPattern":null,"preventionTips":["Never return null from a Not() factory lambda.","When building selectors from data, check for null before passing to Not().","In AXAML, ensure `:not(...)` always contains a selector."],"tags":["avalonia","styling","not-selector","null-argument"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}