PrismLibrary/Prism · error · ArgumentNullException
e
Error message
e
What it means
AutoPopulateRegionBehavior.OnViewRegistered handles ViewRegisteredEventArgs from the view registry and throws ArgumentNullException when the event args e is null. It then matches e.RegionName against the behavior's region and adds the registered view into the region.
Solutions
- Ensure the IRegionViewRegistry always raises ViewRegistered with a non-null ViewRegisteredEventArgs
- Fix custom registry/event-raising code to construct valid event args
- If calling OnViewRegistered directly (e.g. in tests), pass a properly constructed ViewRegisteredEventArgs
Example fix
// before
behavior.OnViewRegistered(this, null);
// after
behavior.OnViewRegistered(this, new ViewRegisteredEventArgs { RegionName = "MyRegion", View = viewFactory }); Defensive patterns
Strategy: validation
Validate before calling
if (args is null) throw new InvalidOperationException("ViewRegisteredEventArgs must be constructed before raising the event"); Try / catch
try { behavior.OnViewRegistered(sender, args); }
catch (ArgumentNullException) { /* registry raised null args; fix event-raising code */ } Prevention
- Always raise ViewRegistered with a constructed ViewRegisteredEventArgs
- In custom registries, validate args before invoking handlers
- In tests, build real event args rather than passing null
When it happens
Trigger: Raising the view-registered callback with null ViewRegisteredEventArgs — i.e. invoking the WeakEvent/subscription path that calls OnViewRegistered(sender, null). Normally only reachable from custom IRegionViewRegistry code or tests firing the event manually.
Common situations: Custom view-registry implementations invoking the handler directly; unit tests simulating view registration with null args; mis-wired weak delegate subscriptions passing null payload.
Related errors
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/6558dd4ed57a2563.
Report an issue: GitHub.
Appendix: source
Thrown at src/Maui/Prism.Maui/Navigation/Regions/Behaviors/AutoPopulateRegionBehavior.cs:110
private void Region_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "Name" && !string.IsNullOrEmpty(Region.Name))
{
Region.PropertyChanged -= Region_PropertyChanged;
StartPopulatingContent();
}
}
/// <summary>
/// Handler of the event that fires when a new viewtype is registered to the registry.
/// </summary>
/// <remarks>Although this is a public method to support Weak Delegates in Silverlight, it should not be called by the user.</remarks>
/// <param name="sender"></param>
/// <param name="e"></param>
public virtual void OnViewRegistered(object sender, ViewRegisteredEventArgs e)
{
if (e == null)
throw new ArgumentNullException(nameof(e));
if (e.RegionName == Region.Name)
{
AddViewIntoRegion((VisualElement)e.GetView(Region.Container()));
}
}
}
View on GitHub (pinned to 358118cd64)