PrismLibrary/Prism · error · ArgumentNullException

region

Error message

region

What it means

LayoutRegionAdapter.Adapt performs a classic null check and throws ArgumentNullException(nameof(region)) when the IRegion passed to the adapter is null. This is an internal contract check - the region manager should never hand a null region to an adapter.

Solutions

  1. Fix the caller so a valid IRegion is obtained from IRegionManager before adapting.
  2. Verify custom IRegionManager/IRegion registrations resolve correctly in the DI container.
  3. Ensure region creation for the control happened (correct region name registration) before adapter code runs.
Defensive patterns

Strategy: type-guard

Validate before calling

if (region is null) return; // or obtain it from IRegionManager.Regions[name]

Type guard

bool TryGetRegion(IRegionManager rm, string name, out IRegion region)
{
    region = rm.Regions.ContainsRegionWithName(name) ? rm.Regions[name] : null;
    return region != null;
}

Prevention

When it happens

Trigger: A null IRegion reaching RegionAdapterBase Adapt - typically from calling regionManager.Regions collection code incorrectly, a broken custom IRegionManager/IRegion implementation, or reflection-driven adapter invocation with a null region.

Common situations: Custom region behaviors or plugins calling adapter.Adapt directly; DI misconfiguration where IRegion resolves to null; test code invoking Adapt with null arguments.

Related errors


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

Appendix: source

Thrown at src/Maui/Prism.Maui/Navigation/Regions/Adapters/LayoutRegionAdapter.cs:28

{
    /// <summary>
    /// Initializes a new instance of <see cref="LayoutRegionAdapter"/>.
    /// </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>

View on GitHub (pinned to 358118cd64)