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
- Use the framework's region implementation (which implements ITargetAwareRegion) instead of a custom one.
- Implement ITargetAwareRegion on your custom region and expose its Container property.
- 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
- Prefer injecting IContainerProvider/services instead of region.Container()
- Don't mock IRegion for code that calls Container()
- Implement ITargetAwareRegion on custom region classes
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
- ArgumentNullException for 'regionName'
- ArgumentNullException for 'regionTarget'
- ArgumentNullException for 'target'
- ArgumentNullException for 'view'
- ArgumentNullException(nameof(behaviorKey))
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)