{"record":{"id":"ac0ed68efdc3a73e","repo":"PrismLibrary/Prism","slug":"the-region-name-cannot-be-null-or-empty","errorCode":null,"errorMessage":"The region name cannot be null or empty.","messagePattern":"The region name cannot be null or empty\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Navigation/Regions/Region.cs","lineNumber":111,"sourceCode":"\n    private string _name;\n    /// <summary>\n    /// Gets the name of the region that uniquely identifies the region within a <see cref=\"IRegionManager\"/>.\n    /// </summary>\n    /// <value>The name of the region.</value>\n    public string Name\n    {\n        get => _name;\n        set\n        {\n            if (_name != null && _name != value)\n            {\n                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CannotChangeRegionNameException, _name));\n            }\n\n            if (string.IsNullOrEmpty(value))\n            {\n                throw new ArgumentException(Resources.RegionNameCannotBeEmptyException);\n            }\n\n            _name = value;\n            RaisePropertyChanged(nameof(Name));\n        }\n    }\n\n    /// <summary>\n    /// Gets or sets the comparison used to sort the views.\n    /// </summary>\n    /// <value>The comparison to use.</value>\n    public Comparison<object> SortComparison\n    {\n        get => _sort;\n        set\n        {\n            _sort = value;\n","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Navigation/Regions/Region.cs#L93-L129","documentation":"Setting Region.Name to null or empty throws ArgumentException (Resources.RegionNameCannotBeEmptyException). The name is the key under which the RegionManager indexes regions, and an empty key would make the region unreachable. Distinct from error 106, which covers renaming; this covers first-time assignment of an invalid value.","triggerScenarios":"region.Name = null; region.Name = \"\"; or a custom region adapter computing the region name from a null/empty string (e.g. a Control whose Name is not set).","commonSituations":"Region adapters deriving names from XAML element names that are missing; dynamic region creation where the name variable is empty; data-bound region name that failed to resolve.","solutions":["Supply a non-empty name when creating the region: new Region { Name = \"ContentRegion\" }.","Validate the name string in the region adapter before assigning.","Ensure the underlying control/element name used to derive the region name is set."],"exampleFix":"// before\nvar region = new Region { Name = control.Name }; // may be empty\n// after\nvar regionName = !string.IsNullOrEmpty(control.Name) ? control.Name : \"ContentRegion\";\nvar region = new Region { Name = regionName };","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(name))\n    throw new ArgumentException(\"Region name must be non-empty\");\nvar region = new Region { Name = name };","typeGuard":"bool IsValidRegionName(string n) => !string.IsNullOrEmpty(n);","tryCatchPattern":"try\n{\n    region.Name = name;\n}\ncatch (ArgumentException)\n{\n    // fall back to a default region name\n}","preventionTips":["Validate the source of the name (control.Name, config) before assignment.","Use nameof(...) or constants for region names.","Check region adapter logic for empty derived names."],"tags":["invalid-argument","empty-string","region","prism"],"backgroundTag":"empty-required-field","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}