{"record":{"id":"01c7b208e2946038","repo":"PrismLibrary/Prism","slug":"region","errorCode":null,"errorMessage":"region","messagePattern":"region","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Navigation/Regions/Adapters/LayoutRegionAdapter.cs","lineNumber":28,"sourceCode":"{\n    /// <summary>\n    /// Initializes a new instance of <see cref=\"LayoutRegionAdapter\"/>.\n    /// </summary>\n    /// <param name=\"regionBehaviorFactory\">The factory used to create the region behaviors to attach to the created regions.</param>\n    public LayoutRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)\n        : base(regionBehaviorFactory)\n    {\n    }\n\n    /// <summary>\n    /// Adapts a <see cref=\"Layout\"/> to an <see cref=\"IRegion\"/>.\n    /// </summary>\n    /// <param name=\"region\">The new region being used.</param>\n    /// <param name=\"regionTarget\">The object to adapt.</param>\n    protected override void Adapt(IRegion region, Layout regionTarget)\n    {\n        if (region == null)\n            throw new ArgumentNullException(nameof(region));\n\n        if (regionTarget == null)\n            throw new ArgumentNullException(nameof(regionTarget));\n\n        bool itemsSourceIsSet = regionTarget.Children?.Any() ?? false || regionTarget.IsSet(BindableLayout.ItemsSourceProperty);\n\n        if (itemsSourceIsSet)\n        {\n            throw new InvalidOperationException(Resources.LayoutViewHasChildrenException);\n        }\n\n        BindableLayout.SetItemsSource(regionTarget, region.Views);\n        BindableLayout.SetItemTemplate(regionTarget, new RegionItemsSourceTemplate());\n    }\n\n    /// <summary>\n    /// Creates a new instance of <see cref=\"IRegion\"/>.\n    /// </summary>","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Navigation/Regions/Adapters/LayoutRegionAdapter.cs#L10-L46","documentation":"LayoutRegionAdapter.Adapt performs a classic null check and throws ArgumentNullException(nameof(region)) when the IRegion passed to the adapter is null. This is an internal contract check - the region manager should never hand a null region to an adapter.","triggerScenarios":"A null IRegion reaching RegionAdapterBase Adapt - typically from calling regionManager.Regions collection code incorrectly, a broken custom IRegionManager/IRegion implementation, or reflection-driven adapter invocation with a null region.","commonSituations":"Custom region behaviors or plugins calling adapter.Adapt directly; DI misconfiguration where IRegion resolves to null; test code invoking Adapt with null arguments.","solutions":["Fix the caller so a valid IRegion is obtained from IRegionManager before adapting.","Verify custom IRegionManager/IRegion registrations resolve correctly in the DI container.","Ensure region creation for the control happened (correct region name registration) before adapter code runs."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"if (region is null) return; // or obtain it from IRegionManager.Regions[name]","typeGuard":"bool TryGetRegion(IRegionManager rm, string name, out IRegion region)\n{\n    region = rm.Regions.ContainsRegionWithName(name) ? rm.Regions[name] : null;\n    return region != null;\n}","tryCatchPattern":null,"preventionTips":["Fetch regions via IRegionManager.Regions[name] rather than caching references.","Verify DI registrations for custom IRegion implementations.","Never invoke adapter.Adapt directly in app code."],"tags":["regions","null-argument","adapter","maui"],"backgroundTag":"null-argument","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}