{"record":{"id":"103e20b64cc96ccb","repo":"PrismLibrary/Prism","slug":"the-region-does-not-implement-icontainerawareregion","errorCode":null,"errorMessage":"The Region does not implement IContainerAwareRegion","messagePattern":"The Region does not implement IContainerAwareRegion","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Navigation/Regions/RegionExtensions.cs","lineNumber":12,"sourceCode":"﻿using Prism.Ioc;\n\nnamespace Prism.Navigation.Regions;\n\ninternal static class RegionExtensions\n{\n    internal static IContainerProvider Container(this IRegion region)\n    {\n        if (region is ITargetAwareRegion car)\n            return car.Container;\n\n        throw new NotSupportedException(\"The Region does not implement IContainerAwareRegion\");\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":15,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Navigation/Regions/RegionExtensions.cs#L1-L15","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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()."],"exampleFix":"// before\npublic class MyRegion : IRegion { /* no ITargetAwareRegion */ }\nvar container = myRegion.Container(); // NotSupportedException\n// after\npublic class MyRegion : IRegion, ITargetAwareRegion\n{\n    public IContainerProvider Container { get; }\n    // ...\n}","handlingStrategy":"type-guard","validationCode":"if (region is not ITargetAwareRegion targetAware)\n    throw new InvalidOperationException(\"Region does not expose a container\");\nvar container = targetAware.Container;","typeGuard":"bool HasContainer(IRegion r) => r is ITargetAwareRegion;","tryCatchPattern":"try { var c = region.Container(); }\ncatch (NotSupportedException) { Console.WriteLine(\"Use a container-aware region or resolve services from the app container\"); }","preventionTips":["Prefer injecting IContainerProvider/services instead of region.Container()","Don't mock IRegion for code that calls Container()","Implement ITargetAwareRegion on custom region classes"],"tags":["prism","regions","notsupported","container"],"backgroundTag":"operation-not-supported","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}