{"record":{"id":"124a504b5de1ce9d","repo":"PrismLibrary/Prism","slug":"the-region-manager-does-not-contain-the-0-region","errorCode":null,"errorMessage":"The region manager does not contain the {0} region.","messagePattern":"The region manager does not contain the (.+?) region\\.","errorType":"exception","errorClass":"KeyNotFoundException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Navigation/Regions/RegionCollection.cs","lineNumber":40,"sourceCode":"    {\n        Xaml.RegionManager.UpdateRegions();\n\n        return _regions.GetEnumerator();\n    }\n\n    IEnumerator IEnumerable.GetEnumerator() =>\n        GetEnumerator();\n\n    public IRegion this[string regionName]\n    {\n        get\n        {\n            Xaml.RegionManager.UpdateRegions();\n\n            IRegion region = GetRegionByName(regionName);\n            if (region == null)\n            {\n                throw new KeyNotFoundException(string.Format(CultureInfo.CurrentUICulture, Resources.RegionNotInRegionManagerException, regionName));\n            }\n\n            return region;\n        }\n    }\n\n    public void Add(IRegion region)\n    {\n        if (region == null)\n            throw new ArgumentNullException(nameof(region));\n\n        Xaml.RegionManager.UpdateRegions();\n\n        if (region.Name == null)\n        {\n            throw new InvalidOperationException(Resources.RegionNameCannotBeEmptyException);\n        }\n","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Navigation/Regions/RegionCollection.cs#L22-L58","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the XAML region host has prism:RegionName=\"<exact name>\" and is part of the visual tree.","Fix the region name string — match case and spelling exactly.","For scoped regions, resolve the scoped IRegionManager (e.g. via IRegionManager.GetRegionManager(view) or navigation parameters) rather than the global one.","Use regionManager.ContainsRegion(name) or Regions.ContainsKey(name) before indexing, or TryGet via Regions.","Ensure RegionManager.UpdateRegions() has run / the app initialized regions before access."],"exampleFix":"// before\nvar region = regionManager[\"DetailsRegion\"];\n\n// after\nif (regionManager.Regions.ContainsKey(\"DetailsRegion\"))\n{\n    var region = regionManager[\"DetailsRegion\"];\n}\nelse\n{\n    // log/defer: region not yet created\n}","handlingStrategy":"validation","validationCode":"if (!regionManager.Regions.ContainsKey(regionName)) { /* defer or log */ }","typeGuard":null,"tryCatchPattern":"try { var region = regionManager[regionName]; } catch (KeyNotFoundException ex) { logger.LogError(ex, \"Region {Name} not registered\", regionName); }","preventionTips":["Verify prism:RegionName attributes in XAML match lookup strings exactly","Access regions only after the host view is loaded and regions discovered","For scoped regions, fetch the scoped IRegionManager rather than the global one","Use ContainsKey/ContainsRegion checks instead of direct indexing"],"tags":["prism","maui","regions","key-not-found"],"backgroundTag":"resource-not-found","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}