{"record":{"id":"a98d62dc1dd71bb4","repo":"PrismLibrary/Prism","slug":"resources-regionnamecannotbeemptyexception","errorCode":null,"errorMessage":"Resources.RegionNameCannotBeEmptyException","messagePattern":"Resources\\.RegionNameCannotBeEmptyException","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Wpf/Prism.Wpf/Navigation/Regions/Region.cs","lineNumber":82,"sourceCode":"\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\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                OnPropertyChanged(nameof(Name));\n            }\n        }\n\n        /// <summary>\n        /// Gets a readonly view of the collection of views in the region.\n        /// </summary>\n        /// <value>An <see cref=\"IViewsCollection\"/> of all the added views.</value>\n        public virtual IViewsCollection Views\n        {\n            get\n            {\n                if (_views == null)\n                {\n                    _views = new ViewsCollection(ItemMetadataCollection, x => true)","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Wpf/Prism.Wpf/Navigation/Regions/Region.cs#L64-L100","documentation":"Region.Name must be a non-empty string; the setter validates the incoming value and throws ArgumentException with RegionNameCannotBeEmptyException when null or empty is supplied. Region names are the lookup keys in RegionManager, so an empty name would be unusable.","triggerScenarios":"Assigning null, empty string, or whitespace-only string to Region.Name — e.g. region.Name = null; or a XAML-bound RegionName whose binding evaluates to empty.","commonSituations":"Data binding for RegionName that has not been initialized yet; constructing regions from configuration files where the name field is missing; refactoring that renamed a resource string used as the region name.","solutions":["Ensure the region name is a non-empty string before assigning: check string.IsNullOrWhiteSpace first.","Fix the source of the empty value (missing XAML attribute, unset binding, missing config key).","If a placeholder is needed, defer region creation until a valid name is available."],"exampleFix":"// before\nregion.Name = config.RegionName; // may be null/empty\n// after\nif (!string.IsNullOrWhiteSpace(config.RegionName))\n{\n    region.Name = config.RegionName;\n}","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(name))\n    throw new ArgumentException(\"Region name must be non-empty.\");\nregion.Name = name;","typeGuard":null,"tryCatchPattern":"try\n{\n    region.Name = name;\n}\ncatch (ArgumentException ex)\n{\n    logger.LogError(ex, \"Invalid region name supplied.\");\n}","preventionTips":["Validate region names with string.IsNullOrWhiteSpace before assignment.","Ensure XAML RegionName bindings always produce non-empty values.","Fail fast at config-load time when a region name key is missing."],"tags":["wpf","prism","region","argument","empty-string"],"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"}