{"record":{"id":"6578c6d0dbf2a266","repo":"PrismLibrary/Prism","slug":"resources-regioncreationexception","errorCode":null,"errorMessage":"Resources.RegionCreationException","messagePattern":"Resources\\.RegionCreationException","errorType":"exception","errorClass":"RegionCreationException","httpStatus":null,"severity":"error","filePath":"src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/DelayedRegionCreationBehavior.cs","lineNumber":131,"sourceCode":"        /// <param name=\"targetElement\">The target element that will host the <see cref=\"IRegion\"/>.</param>\n        /// <param name=\"regionName\">Name of the region.</param>\n        /// <returns>The created <see cref=\"IRegion\"/></returns>\n        protected virtual IRegion CreateRegion(DependencyObject targetElement, string regionName)\n        {\n            if (targetElement == null)\n                throw new ArgumentNullException(nameof(targetElement));\n\n            try\n            {\n                // Build the region\n                IRegionAdapter regionAdapter = _regionAdapterMappings.GetMapping(targetElement.GetType());\n                IRegion region = regionAdapter.Initialize(targetElement, regionName);\n\n                return region;\n            }\n            catch (Exception ex)\n            {\n                throw new RegionCreationException(string.Format(CultureInfo.CurrentCulture, Resources.RegionCreationException, regionName, ex), ex);\n            }\n        }\n\n#if !AVALONIA\n        private void ElementLoaded(object sender, RoutedEventArgs e)\n#else\n        private void ElementLoaded(object sender, VisualTreeAttachmentEventArgs e)\n#endif\n        {\n            UnWireTargetElement();\n            TryCreateRegion();\n        }\n\n        private void WireUpTargetElement()\n        {\n            FrameworkElement element = TargetElement as FrameworkElement;\n            if (element != null)\n            {","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/DelayedRegionCreationBehavior.cs#L113-L149","documentation":"DelayedRegionCreationBehavior.CreateRegion asks the configured IRegionAdapter to initialize the region and wraps any exception in RegionCreationException with Resources.RegionCreationException, including regionName and the original exception. Prism throws this so failures during delayed region creation (e.g., after a control loads) surface with context about which region failed and why.","triggerScenarios":"RegionManager.RegionName attached property set on an element whose adapter's Initialize throws: no IRegionAdapter registered for the control's type, adapter throws internally, or the element is not of an adaptable type.","commonSituations":"Using a custom control without registering a region adapter for its type via RegionAdapterMappings; Prism.Wpf upgraded and a third-party adapter removed; adapter dependencies (like the region behavior factory) misconfigured in the container.","solutions":["Inspect the InnerException — RegionCreationException wraps the real failure.","Register an adapter mapping for the control type: regionAdapterMappings.RegisterMapping(typeof(MyControl), myAdapter).","Ensure the container registration for IRegionAdapter/RegionAdapterMappings matches the Prism version in use.","Verify the target element type is one of the supported controls (ContentControl, ItemsControl, Selector) or has a custom adapter."],"exampleFix":"// before\n// custom control without mapping\nRegionManager.SetRegionName(myCustomControl, \"MainRegion\");\n// after\nvar mappings = container.Resolve<RegionAdapterMappings>();\nmappings.RegisterMapping(typeof(MyCustomControl), new MyCustomControlRegionAdapter());","handlingStrategy":"try-catch","validationCode":"var mappings = regionManager.GetRegionAdapterMappings?.Invoke(); // ensure mapping exists\nif (mappings != null && !mappings.HasMapping(element.GetType()))\n    logger.LogWarning(\"No region adapter registered for {0}\", element.GetType().Name);","typeGuard":null,"tryCatchPattern":"try\n{\n    regionManager.SetRegionName(element, regionName);\n    RegionManager.SetRegionManager(element, regionManager);\n}\ncatch (RegionCreationException ex)\n{\n    logger.LogError(ex.InnerException ?? ex, \"Region '{0}' creation failed\", regionName);\n}","preventionTips":["Always inspect InnerException of RegionCreationException","Register region adapter mappings for custom control types","Keep Prism adapter registrations in sync with the Prism version"],"tags":["wpf","regions","region-adapter","creation-failed"],"backgroundTag":"module-init-failed","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"}