PrismLibrary/Prism · error · ArgumentException

Resources.RegionNameExistsException (formatted with…

Error message

Resources.RegionNameExistsException (formatted with region.Name)

What it means

RegionCollection.Add(IRegion) throws ArgumentException when a region with the same Name is already registered in the RegionManager. Region names must be unique within a RegionCollection, so adding a duplicate-named region is rejected via Resources.RegionNameExistsException formatted with the offending region.Name.

Solutions

  1. Check Regions.ContainsRegionWithName(region.Name) before adding and skip or reuse the existing region.
  2. Remove the existing region first (Regions.Remove) if replacement is intended.
  3. Ensure each region gets a unique name; audit duplicate registration code paths (XAML + code-behind, OnAppearing handlers).

Example fix

// before
regionManager.Regions.Add(new Region { Name = "MainRegion" });
// after
if (!regionManager.Regions.ContainsRegionWithName("MainRegion"))
    regionManager.Regions.Add(new Region { Name = "MainRegion" });
Defensive patterns

Strategy: validation

Validate before calling

if (region != null && !regionManager.Regions.ContainsRegionWithName(region.Name))
    regionManager.Regions.Add(region);

Type guard

bool IsRegionRegistered(IRegionCollection regions, IRegion r) => r?.Name != null && regions.ContainsRegionWithName(r.Name);

Try / catch

try { regionManager.Regions.Add(region); }
catch (ArgumentException ex) { Console.WriteLine($"Region '{region?.Name}' already exists: {ex.Message}"); }

Prevention

When it happens

Trigger: Calling regionManager.Regions.Add(region) (or Add(regionName, region)) when GetRegionByName(region.Name) already returns a region — i.e. a region with that exact Name string is already registered.

Common situations: Registering the same view/region twice during app startup (e.g. both XAML and code-behind registration), re-running initialization on page recreation in MAUI, or two regions accidentally assigned the same x:Name/string name.

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


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

Appendix: source

Thrown at src/Maui/Prism.Maui/Navigation/Regions/RegionCollection.cs:61

            return region;
        }
    }

    public void Add(IRegion region)
    {
        if (region == null)
            throw new ArgumentNullException(nameof(region));

        Xaml.RegionManager.UpdateRegions();

        if (region.Name == null)
        {
            throw new InvalidOperationException(Resources.RegionNameCannotBeEmptyException);
        }

        if (GetRegionByName(region.Name) != null)
        {
            throw new ArgumentException(string.Format(CultureInfo.InvariantCulture,
                                                      Resources.RegionNameExistsException, region.Name));
        }

        _regions.Add(region);
        region.RegionManager = regionManager;

        OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, region, 0));
    }

    public bool Remove(string regionName)
    {
        Xaml.RegionManager.UpdateRegions();

        bool removed = false;

        IRegion region = GetRegionByName(regionName);
        if (region != null)
        {

View on GitHub (pinned to 358118cd64)