PrismLibrary/Prism · error · ArgumentNullException

view

Error message

view

What it means

Region.GetItemMetadataOrThrow throws ArgumentNullException for the 'view' parameter when Remove/activation bookkeeping is handed a null view. It looks up the view's ItemMetadata first, so a null instance fails immediately.

Solutions

  1. Null-check the view before calling region.Remove/view operations.
  2. Check the result of region.GetView(name) for null before using it.
  3. Determine why the view variable is null — usually a failed earlier lookup or an unset field.

Example fix

// before
region.Remove(region.GetView("details"));

// after
var view = region.GetView("details");
if (view != null) region.Remove(view);
Defensive patterns

Strategy: validation

Validate before calling

if (view == null) return;

Type guard

static bool IsRemovable(IRegion region, object view) => view != null && region.Views.Contains(view);

Try / catch

try { region.Remove(view); } catch (ArgumentNullException ex) { logger.LogWarning(ex, "Remove called with null view"); }

Prevention

When it happens

Trigger: Calling region.Remove(null), or a Remove call where the view variable is null because a previous GetView/lookup returned null and was not checked.

Common situations: Chained code like region.Remove(region.GetView(name)) where GetView returned null; null flowing from a failed navigation resolution.

Related errors


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

Appendix: source

Thrown at src/Maui/Prism.Maui/Navigation/Regions/Region.cs:347

            visualElement.ClearValue(Xaml.RegionManager.RegionManagerProperty);
        }
    }

    /// <summary>
    /// 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

View on GitHub (pinned to 358118cd64)