PrismLibrary/Prism · error · KeyNotFoundException

The region manager does not contain the

Error message

The region manager does not contain the {0} region.

What it means

RegionCollection's indexer throws KeyNotFoundException (Resources.RegionNotInRegionManagerException formatted with the region name) when the requested region name is not registered with this IRegionManager. After UpdateRegions() runs, the indexer looks the name up and finds nothing.

Solutions

  1. Verify the XAML region host has prism:RegionName="<exact name>" and is part of the visual tree.
  2. Fix the region name string — match case and spelling exactly.
  3. For scoped regions, resolve the scoped IRegionManager (e.g. via IRegionManager.GetRegionManager(view) or navigation parameters) rather than the global one.
  4. Use regionManager.ContainsRegion(name) or Regions.ContainsKey(name) before indexing, or TryGet via Regions.
  5. Ensure RegionManager.UpdateRegions() has run / the app initialized regions before access.

Example fix

// before
var region = regionManager["DetailsRegion"];

// after
if (regionManager.Regions.ContainsKey("DetailsRegion"))
{
    var region = regionManager["DetailsRegion"];
}
else
{
    // log/defer: region not yet created
}
Defensive patterns

Strategy: validation

Validate before calling

if (!regionManager.Regions.ContainsKey(regionName)) { /* defer or log */ }

Try / catch

try { var region = regionManager[regionName]; } catch (KeyNotFoundException ex) { logger.LogError(ex, "Region {Name} not registered", regionName); }

Prevention

When it happens

Trigger: regionManager["SomeRegion"] where 'SomeRegion' was never registered (no RegionName xaml attribute, no RegisterForNavigation-to-region wiring, no regionManager.Add), or the name is misspelled / differently cased.

Common situations: XAML ContentControl prism:RegionName="MyRegion" missing or misspelled while code accesses regionManager["MyRegion"]; accessing regions before the view is loaded/attached so regions are not yet discovered; scoped regions where the region lives on a child RegionManager, not the one queried.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

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

    {
        Xaml.RegionManager.UpdateRegions();

        return _regions.GetEnumerator();
    }

    IEnumerator IEnumerable.GetEnumerator() =>
        GetEnumerator();

    public IRegion this[string regionName]
    {
        get
        {
            Xaml.RegionManager.UpdateRegions();

            IRegion region = GetRegionByName(regionName);
            if (region == null)
            {
                throw new KeyNotFoundException(string.Format(CultureInfo.CurrentUICulture, Resources.RegionNotInRegionManagerException, regionName));
            }

            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);
        }

View on GitHub (pinned to 358118cd64)