PrismLibrary/Prism · error · RegionCreationException
Resources.RegionCreationException
Error message
Resources.RegionCreationException
What it means
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.
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.
Example fix
// before // custom control without mapping RegionManager.SetRegionName(myCustomControl, "MainRegion"); // after var mappings = container.Resolve<RegionAdapterMappings>(); mappings.RegisterMapping(typeof(MyCustomControl), new MyCustomControlRegionAdapter());
Defensive patterns
Strategy: try-catch
Validate before calling
var mappings = regionManager.GetRegionAdapterMappings?.Invoke(); // ensure mapping exists
if (mappings != null && !mappings.HasMapping(element.GetType()))
logger.LogWarning("No region adapter registered for {0}", element.GetType().Name); Try / catch
try
{
regionManager.SetRegionName(element, regionName);
RegionManager.SetRegionManager(element, regionManager);
}
catch (RegionCreationException ex)
{
logger.LogError(ex.InnerException ?? ex, "Region '{0}' creation failed", regionName);
} Prevention
- Always inspect InnerException of RegionCreationException
- Register region adapter mappings for custom control types
- Keep Prism adapter registrations in sync with the Prism version
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- An exception occurred while creating a region with name
- Resources.DeactiveNotPossibleException
- Resources.HostControlCannotBeSetAfterAttach
- Resources.ItemsControlHasItemsSourceException
- Resources.HostControlCannotBeSetAfterAttach
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/6578c6d0dbf2a266.
Report an issue: GitHub.
Appendix: source
Thrown at src/Wpf/Prism.Wpf/Navigation/Regions/Behaviors/DelayedRegionCreationBehavior.cs:131
/// <param name="targetElement">The target element that will host the <see cref="IRegion"/>.</param>
/// <param name="regionName">Name of the region.</param>
/// <returns>The created <see cref="IRegion"/></returns>
protected virtual IRegion CreateRegion(DependencyObject targetElement, string regionName)
{
if (targetElement == null)
throw new ArgumentNullException(nameof(targetElement));
try
{
// Build the region
IRegionAdapter regionAdapter = _regionAdapterMappings.GetMapping(targetElement.GetType());
IRegion region = regionAdapter.Initialize(targetElement, regionName);
return region;
}
catch (Exception ex)
{
throw new RegionCreationException(string.Format(CultureInfo.CurrentCulture, Resources.RegionCreationException, regionName, ex), ex);
}
}
#if !AVALONIA
private void ElementLoaded(object sender, RoutedEventArgs e)
#else
private void ElementLoaded(object sender, VisualTreeAttachmentEventArgs e)
#endif
{
UnWireTargetElement();
TryCreateRegion();
}
private void WireUpTargetElement()
{
FrameworkElement element = TargetElement as FrameworkElement;
if (element != null)
{View on GitHub (pinned to 358118cd64)