{"record":{"id":"93df5540df5af05a","repo":"PrismLibrary/Prism","slug":"resources-regionnotfound-formatted-with-regionname","errorCode":null,"errorMessage":"Resources.RegionNotFound (formatted with regionName)","messagePattern":"Resources\\.RegionNotFound \\(formatted with regionName\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Navigation/Regions/RegionManager.cs","lineNumber":37,"sourceCode":"        Regions = new RegionCollection(this);\n    }\n\n    /// <summary>\n    /// Gets a collection of <see cref=\"IRegion\"/> that identify each region by name. You can use this collection to add or remove regions to the current region manager.\n    /// </summary>\n    /// <value>A <see cref=\"IRegionCollection\"/> with all the registered regions.</value>\n    public IRegionCollection Regions { get; }\n\n    /// <summary>\n    /// Add a view to the Views collection of a Region. Note that the region must already exist in this <see cref=\"IRegionManager\"/>.\n    /// </summary>\n    /// <param name=\"regionName\">The name of the region to add a view to</param>\n    /// <param name=\"targetName\">The view to add to the views collection</param>\n    /// <returns>The RegionManager, to easily add several views. </returns>\n    public IRegionManager AddToRegion(string regionName, string targetName)\n    {\n        if (!Regions.ContainsRegionWithName(regionName))\n            throw new ArgumentException(string.Format(Thread.CurrentThread.CurrentCulture, Resources.RegionNotFound, regionName), nameof(regionName));\n\n        var region = Regions[regionName];\n        return region.Add(targetName);\n    }\n\n    /// <summary>\n    ///     Add a view to the Views collection of a Region. Note that the region must already exist in this <see cref=\"IRegionManager\"/>.\n    /// </summary>\n    /// <param name=\"regionName\">The name of the region to add a view to</param>\n    /// <param name=\"view\">The view to add to the views collection</param>\n    /// <returns>The RegionManager, to easily add several views. </returns>\n    public IRegionManager AddToRegion(string regionName, object view)\n    {\n        if (!Regions.ContainsRegionWithName(regionName))\n            throw new ArgumentException(string.Format(Thread.CurrentThread.CurrentCulture, Resources.RegionNotFound, regionName), nameof(regionName));\n\n        return Regions[regionName].Add(view);\n    }","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Navigation/Regions/RegionManager.cs#L19-L55","documentation":"RegionManager.AddToRegion(string regionName, string targetName) throws ArgumentException (parameter regionName) when no region with that name is registered — Regions.ContainsRegionWithName(regionName) is false. Resources.RegionNotFound is formatted with the requested name.","triggerScenarios":"Calling regionManager.AddToRegion(\"SomeRegion\", \"ViewName\") when no region named \"SomeRegion\" has been registered or the XAML region name differs in case/spelling.","commonSituations":"Typo or case mismatch between the RegionName in XAML and the string used in code; region not yet created because the containing view hasn't loaded; Prism.MongoDb... no — region adapters missing for the target control so no region was instantiated.","solutions":["Verify the region name matches exactly the RegionName registered in XAML/code (case-sensitive).","Ensure the view containing the region has been created/loaded before calling AddToRegion, or use RegisterViewWithRegion instead.","Check that a region adapter exists for the hosting control so the region is actually created."],"exampleFix":"// before\nregionManager.AddToRegion(\"MainreGion\", \"MyView\"); // typo/case mismatch\n// after\nif (regionManager.Regions.ContainsRegionWithName(\"MainRegion\"))\n    regionManager.AddToRegion(\"MainRegion\", \"MyView\");","handlingStrategy":"validation","validationCode":"if (!regionManager.Regions.ContainsRegionWithName(regionName))\n    throw new InvalidOperationException($\"Region '{regionName}' is not registered\");\nregionManager.AddToRegion(regionName, targetName);","typeGuard":"bool RegionExists(IRegionManager rm, string name) => rm.Regions.ContainsRegionWithName(name);","tryCatchPattern":"try { regionManager.AddToRegion(regionName, targetName); }\ncatch (ArgumentException ex) { Console.WriteLine($\"Region '{regionName}' not found: {ex.Message}\"); }","preventionTips":["Use string constants for region names","Register views with RegisterViewWithRegion instead of imperative AddToRegion when possible","Ensure host views are created before targeting their regions"],"tags":["prism","regions","region-not-found","argumentexception"],"backgroundTag":"resource-not-found","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"}