PrismLibrary/Prism · error · KeyNotFoundException

Resources.NoRegionAdapterException

Error message

Resources.NoRegionAdapterException

What it means

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.

Solutions

  1. Register an adapter for the control type: mappings.RegisterMapping(typeof(MyControl), new MyControlAdapter()) — or via containerRegistry.RegisterAdapterForSpecificType<TControl, TAdapter>().
  2. Derive the control from a supported base (ContentControl, ItemsControl, Selector, TabControl) so it inherits an existing mapping.
  3. Write a custom IRegionAdapter (derive from RegionAdapterBase<MyControl>) for full control over region behavior.

Example fix

// before
<controls:MyGrid prisms:RegionManager.RegionName="MainRegion" /> <!-- no adapter -->
// after
containerRegistry.RegisterAdapterForSpecificType<MyGrid, MyGridRegionAdapter>();
Defensive patterns

Strategy: validation

Validate before calling

if (mappings.GetMappingOrDefault(controlType) == null)
    throw new InvalidOperationException($"No region adapter registered for {controlType.Name}.");

Try / catch

try
{
    var adapter = mappings.GetMapping(control.GetType());
}
catch (KeyNotFoundException ex)
{
    logger.LogError(ex, "No region adapter for this control type. Register one at startup.");
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at src/Wpf/Prism.Wpf/Navigation/Regions/RegionAdapterMappings.cs:80

        /// If there is no registered type for <paramref name="controlType"/> or any of its ancestors,
        /// an exception will be thrown.</remarks>
        /// <exception cref="KeyNotFoundException">When there is no registered type for <paramref name="controlType"/> or any of its ancestors.</exception>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "controlType")]
        public IRegionAdapter GetMapping(Type controlType)
        {
            Type currentType = controlType;

            while (currentType != null)
            {
                if (mappings.ContainsKey(currentType))
                {
                    return mappings[currentType];
                }

                currentType = currentType.BaseType;
            }

            throw new KeyNotFoundException(string.Format(CultureInfo.CurrentCulture, Resources.NoRegionAdapterException, controlType));
        }

        /// <summary>
        /// Returns the adapter associated with the type provided.
        /// </summary>
        /// <typeparam name="T">The control type used to obtain the <see cref="IRegionAdapter"/> mapped.</typeparam>
        /// <returns>The <see cref="IRegionAdapter"/> mapped to the <typeparamref name="T"/>.</returns>
        /// <remarks>This class will look for a registered type for <typeparamref name="T"/> and if there is not any,
        /// it will look for a registered type for any of its ancestors in the class hierarchy.
        /// If there is no registered type for <typeparamref name="T"/> or any of its ancestors,
        /// an exception will be thrown.</remarks>
        /// <exception cref="KeyNotFoundException">When there is no registered type for <typeparamref name="T"/> or any of its ancestors.</exception>
        public IRegionAdapter GetMapping<T>()
        {
            return GetMapping(typeof(T));
        }
    }
}

View on GitHub (pinned to 358118cd64)