{"record":{"id":"3cc0f7b0b6b21264","repo":"MudBlazor/MudBlazor","slug":"the-category-name-cannot-be-null-nor-empty","errorCode":null,"errorMessage":"The category name cannot be null nor empty.","messagePattern":"The category name cannot be null nor empty\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/MudBlazor/Attributes/CategoryAttribute.cs","lineNumber":19,"sourceCode":"﻿using MudBlazor.Charts;\nnamespace MudBlazor\n{\n\n    /// <summary>\n    /// Groups a MudBlazor component parameter under a named category on its API documentation page.\n    /// </summary>\n    /// <remarks>\n    /// Use this attribute together with the <see cref=\"Microsoft.AspNetCore.Components.ParameterAttribute\"/>. <br/>\n    /// This attribute is similar to <see cref=\"System.ComponentModel.CategoryAttribute\"/>. <br/>\n    /// The name of the category can be specified by using a constant defined in the <see cref=\"CategoryTypes\"/> class.\n    /// </remarks>\n    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]\n    public class CategoryAttribute : Attribute\n    {\n        public CategoryAttribute(string name)\n        {\n            if (string.IsNullOrEmpty(name))\n                throw new ArgumentException(\"The category name cannot be null nor empty.\");\n            if (!_categoryOrder.ContainsKey(name))\n                throw new ArgumentException($\"The given category name '{name}' isn't in the categoryOrder field.\");\n            Name = name;\n        }\n\n        /// <summary> The name of the category. </summary>\n        public string Name { get; }\n\n        /// <summary> The order of the category - the greater the number the lower the category will be displayed in the API documentation. </summary>\n        public int Order => _categoryOrder[Name];\n\n        // Possible categories of component properties and the order in which they are displayed in the API documentation.\n        private static readonly Dictionary<string, int> _categoryOrder = new()\n        {\n            [\"Data\"] = 0, // general category\n            [\"Validation\"] = 1, // general category\n\n            // specific categories associated with data","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/MudBlazor/MudBlazor/blob/bdb3acd5ddc0a563428488e7afef0d99549f7a6c/src/MudBlazor/Attributes/CategoryAttribute.cs#L1-L37","documentation":"Thrown by the CategoryAttribute constructor when its name argument is null or an empty string. Every MudBlazor component parameter annotated with [Category(...)] must pass a non-empty category name; the attribute is applied at attribute-instantiation time (i.e. when the type is loaded/reflected), so this is a compile-time/authoring error surfacing at runtime reflection or in the docs API generator.","triggerScenarios":"Writing [Category(\"\")] or [Category(null)] on a MudBlazor component parameter, or computing the name from an expression that resolves to empty (e.g. [Category(SomeConstant)] where the constant is empty).","commonSituations":"Authoring a custom component that inherits MudComponentBase and copying a [Category] attribute without filling in the name; refactor that leaves a placeholder; build of the docs API table reflecting such a property.","solutions":["Provide a non-empty category name, preferably a constant from CategoryTypes (e.g. CategoryTypes.Button.Appearance).","Search the codebase for Category(\"\") / Category(null) and fix the offending attribute.","If you genuinely need no category, simply omit the [Category] attribute."],"exampleFix":"// before\n[Parameter]\n[Category(\"\")]\npublic bool Dense { get; set; }\n\n// after\n[Parameter]\n[Category(CategoryTypes.Button.Appearance)]\npublic bool Dense { get; set; }","handlingStrategy":"validation","validationCode":"var name = CategoryTypes.Button.Appearance;\nif (string.IsNullOrEmpty(name))\n    throw new InvalidOperationException(\"Category name must not be empty.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always source category names from the CategoryTypes constants rather than typing literals.","Run a solution-wide search for Category(\"\") / Category(null) after refactors.","Treat the [Category] attribute as required-on-every-parameter within MudBlazor component authoring."],"tags":["mudblazor","attributes","component-authoring","validation"],"backgroundTag":null,"analyzedSha":"bdb3acd5ddc0a563428488e7afef0d99549f7a6c","analyzedAt":"2026-08-13T19:36:54.040Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}