{"record":{"id":"111e2700ffae6ce8","repo":"PrismLibrary/Prism","slug":"navigationexception-unsupportedmauicreation","errorCode":"NavigationException.UnsupportedMauiCreation","errorMessage":"NavigationException.UnsupportedMauiCreation","messagePattern":"NavigationException\\.UnsupportedMauiCreation","errorType":"exception","errorClass":"NavigationException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Navigation/PageNavigationService.cs","lineNumber":964,"sourceCode":"        {\n            throw new NavigationException(NavigationException.NoPageIsRegistered, segmentName, knfe);\n        }\n        catch(ViewModelCreationException vmce)\n        {\n            throw new NavigationException(NavigationException.ErrorCreatingViewModel, segmentName, _pageAccessor.Page, vmce);\n        }\n        //catch(ViewCreationException viewCreationException)\n        //{\n        //    if(!string.IsNullOrEmpty(viewCreationException.InnerException?.Message) && viewCreationException.InnerException.Message.Contains(\"Maui\"))\n        //        throw new NavigationException(NavigationException.)\n        //}\n        catch (Exception ex)\n        {\n            var inner = ex.InnerException;\n            while(inner is not null)\n            {\n                if (inner.Message.Contains(\"thread with a dispatcher\"))\n                    throw new NavigationException(NavigationException.UnsupportedMauiCreation, segmentName, _pageAccessor.Page, ex);\n                inner = inner.InnerException;\n            }\n            throw new NavigationException(NavigationException.ErrorCreatingPage, segmentName, ex);\n        }\n    }\n\n    protected virtual Page CreatePageFromSegment(string segment)\n    {\n        string segmentName = UriParsingHelper.GetSegmentName(segment);\n        var page = CreatePage(segmentName);\n        if (page is null)\n        {\n            var innerException = new NullReferenceException(string.Format(\"{0} could not be created. Please make sure you have registered {0} for navigation.\", segmentName));\n            throw new NavigationException(NavigationException.NoPageIsRegistered, segmentName, _pageAccessor.Page, innerException);\n        }\n\n        return page;\n    }","sourceCodeStart":946,"sourceCodeEnd":982,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs#L946-L982","documentation":"During page creation Prism walks the exception chain and, if any inner exception message contains 'thread with a dispatcher', concludes that a MAUI UI element was created off the UI thread — an unsupported creation pattern — and throws NavigationException.UnsupportedMauiCreation instead of the generic ErrorCreatingPage.","triggerScenarios":"Navigating (creating a Page/ViewModel) from a background thread or Task.Run so a control's constructor touches main-thread-only APIs, surfacing 'thread with a dispatcher' in the inner exception chain.","commonSituations":"Triggering navigation from an event on a non-UI thread; deep-link handling in a background service; async work that resumes on a non-UI SynchronizationContext and then navigates.","solutions":["Invoke navigation on the main thread: await MainThread.InvokeOnMainThreadAsync(() => _navigationService.NavigateAsync(...))","Remove UI element construction from background threads/Task.Run in constructors or OnInitialized","If in a service/worker, marshal to the dispatcher of the main page (IDispatcherProvider) before navigating"],"exampleFix":"// before\nTask.Run(() => _navigationService.NavigateAsync(\"ViewB\"));\n// after\nawait MainThread.InvokeOnMainThreadAsync(() => _navigationService.NavigateAsync(\"ViewB\"));","handlingStrategy":"try-catch","validationCode":"if (!MainThread.IsMainThread) throw new InvalidOperationException(\"Navigate only on the UI thread\");","typeGuard":null,"tryCatchPattern":"try { await _navigationService.NavigateAsync(segment); }\ncatch (NavigationException ne) when (ne.Message == NavigationException.UnsupportedMauiCreation)\n{ await MainThread.InvokeOnMainThreadAsync(() => _navigationService.NavigateAsync(segment)); }","preventionTips":["Never construct Pages or controls on background threads","Wrap navigation calls in MainThread.InvokeOnMainThreadAsync in services/workers","Avoid Task.Run around navigation and view creation"],"tags":["prism","maui","navigation","threading"],"backgroundTag":"unsupported-platform","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"}