{"record":{"id":"514b17cd42d71d3c","repo":"PrismLibrary/Prism","slug":"element","errorCode":null,"errorMessage":"element","messagePattern":"element","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Navigation/Regions/DefaultRegionManagerAccessor.cs","lineNumber":27,"sourceCode":"    /// </summary>\n    /// <remarks>This event uses weak references to the event handler to prevent this static event of keeping the\n    /// target element longer than expected.</remarks>\n    public event EventHandler UpdatingRegions\n    {\n        add => Xaml.RegionManager.UpdatingRegions += value;\n        remove => Xaml.RegionManager.UpdatingRegions -= value;\n    }\n\n    /// <summary>\n    /// Gets the value for the RegionName attached property.\n    /// </summary>\n    /// <param name=\"element\">The object to adapt. This is typically a container (i.e a control).</param>\n    /// <returns>The name of the region that should be created when\n    /// the RegionManager is also set in this element.</returns>\n    public string GetRegionName(VisualElement element)\n    {\n        if (element == null)\n            throw new ArgumentNullException(nameof(element));\n\n        return element.GetValue(Xaml.RegionManager.RegionNameProperty) as string;\n    }\n\n    /// <summary>\n    /// Gets the value of the RegionName attached property.\n    /// </summary>\n    /// <param name=\"element\">The target element.</param>\n    /// <returns>The <see cref=\"IRegionManager\"/> attached to the <paramref name=\"element\"/> element.</returns>\n    public IRegionManager GetRegionManager(VisualElement element)\n    {\n        if (element == null)\n            throw new ArgumentNullException(nameof(element));\n\n        var regionManager = TryGetRegion(element);\n        if (regionManager is null)\n        {\n            regionManager = ContainerLocator.Container.Resolve<IRegionManager>();","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Navigation/Regions/DefaultRegionManagerAccessor.cs#L9-L45","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nvar name = accessor.GetRegionName(element);\n// after\nvar name = element is null ? null : accessor.GetRegionName(element);","handlingStrategy":"type-guard","validationCode":"var regionName = element is null ? null : DefaultRegionManagerAccessor.Instance.GetRegionName(element);","typeGuard":"string? SafeGetRegionName(VisualElement? e) => e is null ? null : accessor.GetRegionName(e);","tryCatchPattern":"try { name = accessor.GetRegionName(element); }\ncatch (ArgumentNullException) { name = null; }","preventionTips":["Verify element liveness before region queries","Clean up behaviors when their host is unloaded","Filter null children before iterating visual tree for regions"],"tags":["null-argument","regions","attached-property"],"backgroundTag":"null-argument","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}