PrismLibrary/Prism · error · ArgumentNullException
element
Error message
element
What it means
DefaultRegionManagerAccessor.GetRegionName throws ArgumentNullException when the VisualElement parameter 'element' is null. This accessor reads the RegionManager.RegionName attached property from an element so the RegionManager can discover region names.
Solutions
- Ensure the element whose RegionName is queried is alive and attached
- Null-check the element before calling GetRegionName
- Fix the behavior setup so it does not outlive its target control
- Guard against recycled/virtualized template elements that can be null
Example fix
// before var name = accessor.GetRegionName(element); // after var name = element is null ? null : accessor.GetRegionName(element);
Defensive patterns
Strategy: type-guard
Validate before calling
var regionName = element is null ? null : DefaultRegionManagerAccessor.Instance.GetRegionName(element);
Type guard
string? SafeGetRegionName(VisualElement? e) => e is null ? null : accessor.GetRegionName(e);
Try / catch
try { name = accessor.GetRegionName(element); }
catch (ArgumentNullException) { name = null; } Prevention
- Verify element liveness before region queries
- Clean up behaviors when their host is unloaded
- Filter null children before iterating visual tree for regions
When it happens
Trigger: Passing null to GetRegionName — typically from a region behavior whose target element reference was lost (expired weak reference, unloaded control) or from custom code querying a region name on a non-existent element.
Common situations: Region behaviors surviving after their host was removed from the visual tree; custom region code paths iterating visual-tree children that include nulls; tests calling the accessor without an element.
Related errors
- target
- ArgumentNullException for 'regionTarget'
- candidateNavigationContract
- e
- Object reference not set (ArgumentNullException for…
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/514b17cd42d71d3c.
Report an issue: GitHub.
Appendix: source
Thrown at src/Maui/Prism.Maui/Navigation/Regions/DefaultRegionManagerAccessor.cs:27
/// </summary>
/// <remarks>This event uses weak references to the event handler to prevent this static event of keeping the
/// target element longer than expected.</remarks>
public event EventHandler UpdatingRegions
{
add => Xaml.RegionManager.UpdatingRegions += value;
remove => Xaml.RegionManager.UpdatingRegions -= value;
}
/// <summary>
/// Gets the value for the RegionName attached property.
/// </summary>
/// <param name="element">The object to adapt. This is typically a container (i.e a control).</param>
/// <returns>The name of the region that should be created when
/// the RegionManager is also set in this element.</returns>
public string GetRegionName(VisualElement element)
{
if (element == null)
throw new ArgumentNullException(nameof(element));
return element.GetValue(Xaml.RegionManager.RegionNameProperty) as string;
}
/// <summary>
/// Gets the value of the RegionName attached property.
/// </summary>
/// <param name="element">The target element.</param>
/// <returns>The <see cref="IRegionManager"/> attached to the <paramref name="element"/> element.</returns>
public IRegionManager GetRegionManager(VisualElement element)
{
if (element == null)
throw new ArgumentNullException(nameof(element));
var regionManager = TryGetRegion(element);
if (regionManager is null)
{
regionManager = ContainerLocator.Container.Resolve<IRegionManager>();View on GitHub (pinned to 358118cd64)