{"record":{"id":"7a87a8e74df29b2b","repo":"PrismLibrary/Prism","slug":"resources-onviewregisteredexception-formatted-with-e","errorCode":null,"errorMessage":"Resources.OnViewRegisteredException (formatted with e.RegionName, rootException)","messagePattern":"Resources\\.OnViewRegisteredException \\(formatted with e\\.RegionName, rootException\\)","errorType":"exception","errorClass":"ViewRegistrationException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Navigation/Regions/RegionViewRegistry.cs","lineNumber":106,"sourceCode":"    private void OnContentRegistered(ViewRegisteredEventArgs e)\n    {\n        try\n        {\n            _contentRegisteredListeners.Raise(this, e);\n        }\n        catch (TargetInvocationException ex)\n        {\n            Exception rootException;\n            if (ex.InnerException != null)\n            {\n                rootException = ex.InnerException.GetRootException();\n            }\n            else\n            {\n                rootException = ex.GetRootException();\n            }\n\n            throw new ViewRegistrationException(string.Format(CultureInfo.CurrentCulture,\n                Resources.OnViewRegisteredException, e.RegionName, rootException), ex.InnerException);\n        }\n    }\n}\n","sourceCodeStart":88,"sourceCodeEnd":111,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Navigation/Regions/RegionViewRegistry.cs#L88-L111","documentation":"Prism.Maui wraps an exception thrown while registering a view with a region in a ViewRegistrationException. It formats Resources.OnViewRegisteredException with the region name and the root (innermost) exception, preserving the original as InnerException. This exists so region wiring failures surface a clear message naming the offending region instead of an opaque internal error.","triggerScenarios":"The ContentRegistered event handler (OnContentRegistered) catches an exception raised by a view registry adapter (e.g. IRegionAdapter creation for the registered view/region) and rethrows it via OnViewRegisteredException. Any failure inside region adapter creation, view resolution, or region behavior attachment during RegisterViewWithRegion triggers it.","commonSituations":"View type not registered in the DI container when a region tries to create it; region adapter missing for the target control; a region behavior throwing during attachment; typo'd region name registered with a nonexistent adapter.","solutions":["Inspect InnerException (rootException) to find the real failure and fix that underlying issue.","Ensure the view type is registered in the container before RegisterViewWithRegion is called.","Verify a region adapter exists for the control hosting the region (or register one).","Check the region name matches the registered name exactly (case/typo)."],"exampleFix":"// before: ViewRegistrationException with opaque inner stack\ncontainerRegistry.RegisterForNavigation<MyRegionView>(); // missing\n// after: register the view and adapter first\ncontainerRegistry.RegisterForNavigation<MyRegionView>();\ncontainerRegistry.RegisterForNavigation<MyContentControlAdapter>();","handlingStrategy":"try-catch","validationCode":"if (containerRegistry == null || view == null || string.IsNullOrWhiteSpace(regionName)) throw new InvalidOperationException(\"Invalid region registration inputs\");","typeGuard":"if (string.IsNullOrWhiteSpace(regionName) || view is null) return;","tryCatchPattern":"try\n{\n    regionManager.RegisterViewWithRegion(regionName, viewType);\n}\ncatch (ViewRegistrationException ex)\n{\n    logger.LogError(ex.InnerException ?? ex, \"View registration failed for region {Region}\", regionName);\n}","preventionTips":["Register all region views with the DI container before navigation.","Confirm a region adapter exists for each host control type.","Log InnerException — the wrapper hides the real cause."],"tags":["prism","maui","regions","view-registration","wrapped-exception"],"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"}