{"record":{"id":"8633e44968436a3d","repo":"AvaloniaUI/Avalonia","slug":"name-may-not-be-empty","errorCode":null,"errorMessage":"Name may not be empty","messagePattern":"Name may not be empty","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Styling/Selectors.cs","lineNumber":33,"sourceCode":"        /// <returns>The selector.</returns>\n        public static Selector Child(this Selector previous)\n        {\n            return new ChildSelector(previous);\n        }\n\n        /// <summary>\n        /// Returns a selector which matches a control's style class.\n        /// </summary>\n        /// <param name=\"previous\">The previous selector.</param>\n        /// <param name=\"name\">The name of the style class.</param>\n        /// <returns>The selector.</returns>\n        public static Selector Class(this Selector? previous, string name)\n        {\n            _ = name ?? throw new ArgumentNullException(nameof(name));\n\n            if (string.IsNullOrWhiteSpace(name))\n            {\n                throw new ArgumentException(\"Name may not be empty\", nameof(name));\n            }\n\n            var tac = previous as TypeNameAndClassSelector;\n\n            if (tac != null)\n            {\n                tac.Classes.Add(name);\n                return tac;\n            }\n            else\n            {\n                return TypeNameAndClassSelector.ForClass(previous, name);\n            }\n        }\n\n        /// <summary>\n        /// Returns a selector which matches a descendant of a previous selector.\n        /// </summary>","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Styling/Selectors.cs#L15-L51","documentation":"Thrown by Selectors.Class() when the class name is null, empty, or whitespace. Style class names must be non-empty tokens; a blank name cannot match any class and usually signals a data or markup mistake. Note a null name throws ArgumentNullException first, so this ArgumentException covers empty/whitespace.","triggerScenarios":"Calling `selector.Class(\"\")`, `selector.Class(\"   \")`, or passing a variable that resolves to whitespace. In AXAML, a malformed class selector like `. ` or `Button.` with no name.","commonSituations":"Building class selectors from data that may be blank; trailing/leading whitespace in dynamic class names; AXAML typo where the class token is omitted after the dot.","solutions":["Provide a non-empty, trimmed class name.","If the name comes from data, validate/trim it and skip the selector when empty.","Check AXAML for stray dots with no following token."],"exampleFix":"// before\nselector = selector.Class(className); // className may be \"\"\n\n// after\nvar name = className?.Trim();\nif (!string.IsNullOrEmpty(name))\n    selector = selector.Class(name);","handlingStrategy":"validation","validationCode":"var name = className?.Trim();\nif (string.IsNullOrEmpty(name))\n    throw new ArgumentException(\"Class name must be non-empty.\", nameof(className));\nselector = selector.Class(name);","typeGuard":"static bool IsValidClassName(string? n) => !string.IsNullOrWhiteSpace(n);","tryCatchPattern":null,"preventionTips":["Trim and check class names before passing to Class().","Skip building the selector when the name is empty.","Audit AXAML for malformed `.token` class selectors."],"tags":["avalonia","styling","class-selector","validation","argument"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}