PrismLibrary/Prism · error · ArgumentNullException
regionTarget
Error message
regionTarget
What it means
LayoutRegionAdapter.Adapt throws ArgumentNullException(nameof(regionTarget)) when the Layout control to be adapted is null. The adapter cannot attach BindableLayout items to a null target, so this is an internal contract violation by the region infrastructure or a custom caller.
Solutions
- Confirm the XAML element with prism:RegionManager.RegionName actually exists and instantiates on the target platform.
- Verify the attached control derives from Layout (the adapter's supported target type).
- Fix custom callers to pass a concrete Layout instance to Adapt.
Defensive patterns
Strategy: type-guard
Validate before calling
if (regionTarget is null) return; // ensure the XAML control resolved on this platform
Type guard
bool TryGetTarget(Layout control, out Layout target)
{
target = control;
return target != null;
} Prevention
- Ensure the region-named control exists on all platforms' XAML.
- Confirm the target control derives from Layout.
- Avoid manipulating adapter targets directly; let the region manager resolve them.
When it happens
Trigger: Adapt called with a null Layout regionTarget - usually from malformed region registration where the control lookup failed (region name attached to a non-existent control) or a custom adapter invocation.
Common situations: XAML region name set on a control that was removed/replaced so the target resolves null; custom code calling the adapter directly; platform-specific layouts that are not real Layout instances.
Related errors
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/5f3d66b27f339d89.
Report an issue: GitHub.
Appendix: source
Thrown at src/Maui/Prism.Maui/Navigation/Regions/Adapters/LayoutRegionAdapter.cs:31
/// </summary>
/// <param name="regionBehaviorFactory">The factory used to create the region behaviors to attach to the created regions.</param>
public LayoutRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)
: base(regionBehaviorFactory)
{
}
/// <summary>
/// Adapts a <see cref="Layout"/> to an <see cref="IRegion"/>.
/// </summary>
/// <param name="region">The new region being used.</param>
/// <param name="regionTarget">The object to adapt.</param>
protected override void Adapt(IRegion region, Layout regionTarget)
{
if (region == null)
throw new ArgumentNullException(nameof(region));
if (regionTarget == null)
throw new ArgumentNullException(nameof(regionTarget));
bool itemsSourceIsSet = regionTarget.Children?.Any() ?? false || regionTarget.IsSet(BindableLayout.ItemsSourceProperty);
if (itemsSourceIsSet)
{
throw new InvalidOperationException(Resources.LayoutViewHasChildrenException);
}
BindableLayout.SetItemsSource(regionTarget, region.Views);
BindableLayout.SetItemTemplate(regionTarget, new RegionItemsSourceTemplate());
}
/// <summary>
/// Creates a new instance of <see cref="IRegion"/>.
/// </summary>
/// <returns>A new instance of <see cref="Region"/>.</returns>
protected override IRegion CreateRegion(IContainerProvider container) =>
container.Resolve<Region>();View on GitHub (pinned to 358118cd64)