{"record":{"id":"62ef9bcaa642197f","repo":"PrismLibrary/Prism","slug":"resources-updateregionexception-formatted-with-rootexception","errorCode":null,"errorMessage":"Resources.UpdateRegionException (formatted with rootException)","messagePattern":"Resources\\.UpdateRegionException \\(formatted with rootException\\)","errorType":"exception","errorClass":"UpdateRegionsException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Navigation/Regions/Xaml/RegionManager.cs","lineNumber":234,"sourceCode":"    }\n\n    /// <summary>\n    /// Notifies attached behaviors to update the region managers appropriately if needed to.\n    /// </summary>\n    /// <remarks>\n    /// This method is normally called internally, and there is usually no need to call this from user code.\n    /// </remarks>\n    public static void UpdateRegions()\n    {\n        try\n        {\n            updatingRegionsListeners.Raise(null, EventArgs.Empty);\n        }\n        catch (TargetInvocationException ex)\n        {\n            Exception rootException = ex.GetRootException();\n\n            throw new UpdateRegionsException(string.Format(CultureInfo.CurrentCulture,\n                Resources.UpdateRegionException, rootException), ex.InnerException);\n        }\n    }\n}\n","sourceCodeStart":216,"sourceCodeEnd":239,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Navigation/Regions/Xaml/RegionManager.cs#L216-L239","documentation":"RegionManager.UpdateRegions raises the UpdatingRegions notification so registered region behaviors re-evaluate pending region registrations. If a listener throws, the exception arrives as TargetInvocationException; Prism unwraps its root exception and rethrows it as UpdateRegionsException (formatted with Resources.UpdateRegionException), preserving the inner exception.","triggerScenarios":"Calling RegionManager.UpdateRegions() when one of the subscribed UpdatingRegions listeners (via UpdateRegions() event subscription) throws — the failure is wrapped in TargetInvocationException and rethrown as UpdateRegionsException.","commonSituations":"Custom region behavior or adapter throwing in its UpdateRegions handler; DI resolution failing inside a listener; timing calls to UpdateRegions before the container is fully configured.","solutions":["Inspect the InnerException to identify which listener failed and fix it.","Wrap listener logic in error handling so a single behavior doesn't break region updates.","Call UpdateRegions only after the container and region adapters are registered.","Remove or fix stale region behavior registrations that reference unresolvable types."],"exampleFix":"// before: listener throws NRE inside UpdateRegions\npublic void OnUpdatingRegions(object s, EventArgs e) => ResolveRegionAdapter(); // may throw\n// after\npublic void OnUpdatingRegions(object s, EventArgs e)\n{\n    try { ResolveRegionAdapter(); }\n    catch (Exception ex) { logger.LogError(ex, \"region update listener failed\"); }\n}","handlingStrategy":"try-catch","validationCode":"// Ensure listeners won't throw before calling\nif (container is null || !container.IsRegistered<IRegionAdapter>()) throw new InvalidOperationException(\"Region adapters not configured\");","typeGuard":null,"tryCatchPattern":"try\n{\n    RegionManager.UpdateRegions();\n}\ncatch (UpdateRegionsException ex)\n{\n    logger.LogError(ex.InnerException ?? ex, \"UpdateRegions listener failed\");\n}","preventionTips":["Wrap every UpdatingRegions listener body in error handling.","Call UpdateRegions only after the container is fully configured.","Inspect InnerException to identify the failing listener."],"tags":["prism","maui","regions","wrapped-exception","target-invocation"],"backgroundTag":"internal-invariant-violation","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"}