PrismLibrary/Prism · error · ArgumentException
The region does not contain the specified view.
Error message
The region does not contain the specified view.
What it means
Region.GetItemMetadataOrThrow throws ArgumentException (Resources.ViewNotInRegionException, param 'view') when the view object is not tracked in the region's ItemMetadataCollection. You can only Remove/deactivate views that were previously Added to this region.
Solutions
- Verify the view exists in the region first: region.Views.Contains(view) before calling Remove.
- Ensure the view was added to THIS region instance (compare RegionManager.RegionNames).
- Make Remove idempotent on your side by tracking removals or wrapping in a Contains check.
- Use RemoveAll() when you intend to clear everything.
Example fix
// before
region.Remove(view); // may throw if absent
// after
if (region.Views.Contains(view))
region.Remove(view); Defensive patterns
Strategy: validation
Validate before calling
if (view == null || !region.Views.Contains(view)) return;
Type guard
static bool BelongsToRegion(IRegion region, object view) => view != null && region.Views.Contains(view);
Try / catch
try { region.Remove(view); } catch (ArgumentException ex) { logger.LogWarning(ex, "View not part of region {Region}", region.Name); } Prevention
- Check region.Views.Contains(view) before Remove
- Keep a 1:1 mapping between views and the region they were added to
- Track removals to make cleanup idempotent and avoid double-remove
When it happens
Trigger: Calling region.Remove(view) for a view instance that was never added to this region, or that was already removed; adding the view to a different region than the one you remove from.
Common situations: Removing views across region instances (stale region reference); double-remove after RemoveAll; assumptions that a view registered globally lives in a specific region.
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
- ArgumentNullException for 'regionTarget'
- ArgumentNullException for 'target'
- ArgumentNullException for 'view'
- Deactivation is not possible in this type of region.
- e
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/b4bbd182bbc5401f.
Report an issue: GitHub.
Appendix: source
Thrown at src/Maui/Prism.Maui/Navigation/Regions/Region.cs:352
/// Removes all views from the region.
/// </summary>
public void RemoveAll()
{
foreach (var view in Views)
{
Remove(view);
}
}
private ItemMetadata GetItemMetadataOrThrow(object view)
{
if (view == null)
throw new ArgumentNullException(nameof(view));
var itemMetadata = ItemMetadataCollection.FirstOrDefault(x => x.Item == view);
if (itemMetadata == null)
throw new ArgumentException(Resources.ViewNotInRegionException, nameof(view));
return itemMetadata;
}
internal static int DefaultSortComparison(object x, object y)
{
if (x == null)
{
if (y == null)
{
return 0;
}
else
{
return -1;
}
}
elseView on GitHub (pinned to 358118cd64)