PrismLibrary/Prism · error · NotSupportedException

The Region does not implement IContainerAwareRegion

Error message

The Region does not implement IContainerAwareRegion

What it means

The internal RegionExtensions.Container(this IRegion) extension throws NotSupportedException when the region does not implement ITargetAwareRegion (historically IContainerAwareRegion). Only container-backed region implementations can expose their IContainerProvider.

Solutions

  1. Use the framework's region implementation (which implements ITargetAwareRegion) instead of a custom one.
  2. Implement ITargetAwareRegion on your custom region and expose its Container property.
  3. Resolve services from the app's IContainerProvider directly instead of via region.Container().

Example fix

// before
public class MyRegion : IRegion { /* no ITargetAwareRegion */ }
var container = myRegion.Container(); // NotSupportedException
// after
public class MyRegion : IRegion, ITargetAwareRegion
{
    public IContainerProvider Container { get; }
    // ...
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (region is not ITargetAwareRegion targetAware)
    throw new InvalidOperationException("Region does not expose a container");
var container = targetAware.Container;

Type guard

bool HasContainer(IRegion r) => r is ITargetAwareRegion;

Try / catch

try { var c = region.Container(); }
catch (NotSupportedException) { Console.WriteLine("Use a container-aware region or resolve services from the app container"); }

Prevention

When it happens

Trigger: Calling region.Container() on any IRegion implementation that is not the framework's container-aware region — e.g. custom IRegion implementations, mocks/stubs, or regions created manually.

Common situations: Unit tests using mocked IRegion instances; custom region classes written before/without implementing ITargetAwareRegion; upgrading Prism where the interface was renamed from IContainerAwareRegion to ITargetAwareRegion.

Related errors


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

Appendix: source

Thrown at src/Maui/Prism.Maui/Navigation/Regions/RegionExtensions.cs:12

using Prism.Ioc;

namespace Prism.Navigation.Regions;

internal static class RegionExtensions
{
    internal static IContainerProvider Container(this IRegion region)
    {
        if (region is ITargetAwareRegion car)
            return car.Container;

        throw new NotSupportedException("The Region does not implement IContainerAwareRegion");
    }
}

View on GitHub (pinned to 358118cd64)