PrismLibrary/Prism · error · ArgumentException

Resources.RegionNameCannotBeEmptyException

Error message

Resources.RegionNameCannotBeEmptyException

What it means

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.

Solutions

  1. Ensure the region name is a non-empty string before assigning: check string.IsNullOrWhiteSpace first.
  2. Fix the source of the empty value (missing XAML attribute, unset binding, missing config key).
  3. If a placeholder is needed, defer region creation until a valid name is available.

Example fix

// before
region.Name = config.RegionName; // may be null/empty
// after
if (!string.IsNullOrWhiteSpace(config.RegionName))
{
    region.Name = config.RegionName;
}
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(name))
    throw new ArgumentException("Region name must be non-empty.");
region.Name = name;

Try / catch

try
{
    region.Name = name;
}
catch (ArgumentException ex)
{
    logger.LogError(ex, "Invalid region name supplied.");
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15). Data as JSON: /api/errors/a98d62dc1dd71bb4. Report an issue: GitHub.

Appendix: source

Thrown at src/Wpf/Prism.Wpf/Navigation/Regions/Region.cs:82

        /// <summary>
        /// Gets the name of the region that uniquely identifies the region within a <see cref="IRegionManager"/>.
        /// </summary>
        /// <value>The name of the region.</value>
        public string Name
        {
            get => _name;

            set
            {
                if (_name != null && _name != value)
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CannotChangeRegionNameException, _name));
                }

                if (string.IsNullOrEmpty(value))
                {
                    throw new ArgumentException(Resources.RegionNameCannotBeEmptyException);
                }

                _name = value;
                OnPropertyChanged(nameof(Name));
            }
        }

        /// <summary>
        /// Gets a readonly view of the collection of views in the region.
        /// </summary>
        /// <value>An <see cref="IViewsCollection"/> of all the added views.</value>
        public virtual IViewsCollection Views
        {
            get
            {
                if (_views == null)
                {
                    _views = new ViewsCollection(ItemMetadataCollection, x => true)

View on GitHub (pinned to 358118cd64)