{"record":{"id":"5030c39ab72c76c1","repo":"PrismLibrary/Prism","slug":"resources-noregionadapterexception","errorCode":null,"errorMessage":"Resources.NoRegionAdapterException","messagePattern":"Resources\\.NoRegionAdapterException","errorType":"exception","errorClass":"KeyNotFoundException","httpStatus":null,"severity":"error","filePath":"src/Wpf/Prism.Wpf/Navigation/Regions/RegionAdapterMappings.cs","lineNumber":80,"sourceCode":"        /// If there is no registered type for <paramref name=\"controlType\"/> or any of its ancestors,\n        /// an exception will be thrown.</remarks>\n        /// <exception cref=\"KeyNotFoundException\">When there is no registered type for <paramref name=\"controlType\"/> or any of its ancestors.</exception>\n        [System.Diagnostics.CodeAnalysis.SuppressMessage(\"Microsoft.Naming\", \"CA2204:Literals should be spelled correctly\", MessageId = \"controlType\")]\n        public IRegionAdapter GetMapping(Type controlType)\n        {\n            Type currentType = controlType;\n\n            while (currentType != null)\n            {\n                if (mappings.ContainsKey(currentType))\n                {\n                    return mappings[currentType];\n                }\n\n                currentType = currentType.BaseType;\n            }\n\n            throw new KeyNotFoundException(string.Format(CultureInfo.CurrentCulture, Resources.NoRegionAdapterException, controlType));\n        }\n\n        /// <summary>\n        /// Returns the adapter associated with the type provided.\n        /// </summary>\n        /// <typeparam name=\"T\">The control type used to obtain the <see cref=\"IRegionAdapter\"/> mapped.</typeparam>\n        /// <returns>The <see cref=\"IRegionAdapter\"/> mapped to the <typeparamref name=\"T\"/>.</returns>\n        /// <remarks>This class will look for a registered type for <typeparamref name=\"T\"/> and if there is not any,\n        /// it will look for a registered type for any of its ancestors in the class hierarchy.\n        /// If there is no registered type for <typeparamref name=\"T\"/> or any of its ancestors,\n        /// an exception will be thrown.</remarks>\n        /// <exception cref=\"KeyNotFoundException\">When there is no registered type for <typeparamref name=\"T\"/> or any of its ancestors.</exception>\n        public IRegionAdapter GetMapping<T>()\n        {\n            return GetMapping(typeof(T));\n        }\n    }\n}","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Wpf/Prism.Wpf/Navigation/Regions/RegionAdapterMappings.cs#L62-L98","documentation":"RegionAdapterMappings.GetMapping walks up the control type hierarchy looking for a registered adapter and throws KeyNotFoundException formatted with NoRegionAdapterException when no mapping exists for controlType or any of its base types. Prism cannot host a region on a control without a registered adapter.","triggerScenarios":"Attaching a RegionName to a control whose type (and all ancestors) has no registered IRegionAdapter — e.g. a custom UserControl or third-party control without mapping — during region initialization.","commonSituations":"Using RegionManager.RegionName on a plain custom control; third-party control libraries whose base classes don't descend from a mapped Prism control; forgetting to register an adapter for a newly added custom control.","solutions":["Register an adapter for the control type: mappings.RegisterMapping(typeof(MyControl), new MyControlAdapter()) — or via containerRegistry.RegisterAdapterForSpecificType<TControl, TAdapter>().","Derive the control from a supported base (ContentControl, ItemsControl, Selector, TabControl) so it inherits an existing mapping.","Write a custom IRegionAdapter (derive from RegionAdapterBase<MyControl>) for full control over region behavior."],"exampleFix":"// before\n<controls:MyGrid prisms:RegionManager.RegionName=\"MainRegion\" /> <!-- no adapter -->\n// after\ncontainerRegistry.RegisterAdapterForSpecificType<MyGrid, MyGridRegionAdapter>();","handlingStrategy":"validation","validationCode":"if (mappings.GetMappingOrDefault(controlType) == null)\n    throw new InvalidOperationException($\"No region adapter registered for {controlType.Name}.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    var adapter = mappings.GetMapping(control.GetType());\n}\ncatch (KeyNotFoundException ex)\n{\n    logger.LogError(ex, \"No region adapter for this control type. Register one at startup.\");\n}","preventionTips":["Register an adapter for every custom control that hosts regions.","Prefer deriving controls from ContentControl/ItemsControl/Selector so built-in adapters apply.","Eagerly verify adapter availability for all region-hosting controls in a startup smoke test."],"tags":["wpf","prism","region-adapter","not-found","mapping"],"backgroundTag":"resource-not-found","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}