Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin Prism Forms: Application windows are expected to have a root view controller at the end of application launch

Solved:

If you are having this error when using Xamarin Forms you should probably check if your initial page is properly constructed. This happens when XF fails to create your initial page and just continues running. It seems that this another case where Xamarin Forms fails to properly display the error which causes a lot of pain to a lot of users when debugging.

  • Platform: Xamarin Forms (iOS & Android)
  • Prism version: 6.2.0
  • Xamarin Forms version: 2.3.3.180
  • Visual Studio 2015
  • Xamarin Studio 6.1.5

Sorry, I am a newbie when it comes to developing mobile applications. Having problems after updating Xamarin Studio, Xamarin Forms, Xamarin for Visual Studio. Can't seem to find a solution for this specific problem; all answers point to changing the AppDelegate FinishedLaunching for Xamarin iOS or iOS Xcode in general.

Unhandled Exception:

Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSInternalInconsistencyException Reason: Application windows are expected to have a root view controller at the end of application launch

Native stack trace:
    0   CoreFoundation                      0x0000000109556d4b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x0000000113f5621e objc_exception_throw + 48
    2   CoreFoundation                      0x000000010955ae42 +[NSException raise:format:arguments:] + 98
    3   Foundation                          0x000000010a13b66d -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
    4   UIKit                               0x000000010ce3091d -[UIApplication _runWithMainScene:transitionContext:completion:] + 3827
    5   UIKit                               0x000000010ce2d26d -[UIApplication workspaceDidEndTransaction:] + 188
    6   FrontBoardServices                  0x0000000116c7f6cb __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
    7   FrontBoardServices                  0x0000000116c7f544 -[FBSSerialQueue _performNext] + 189
    8   FrontBoardServices                  0x0000000116c7f8cd -[FBSSerialQueue _performNextFromRunLoopSource] + 45
    9   CoreFoundation                      0x00000001094fb761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    10  CoreFoundation                      0x00000001094e098c __CFRunLoopDoSources0 + 556
    11  CoreFoundation                      0x00000001094dfe76 __CFRunLoopRun + 918
    12  CoreFoundation                      0x00000001094df884 CFRunLoopRunSpecific + 420
    13  UIKit                               0x000000010ce2baea -[UIApplication _run] + 434
    14  UIKit                               0x000000010ce31c68 UIApplicationMain + 159
    15  ???                                 0x000000012c49543c 0x0 + 5037970492
    16  ???                                 0x000000012c4950ad 0x0 + 5037969581
like image 825
M.Ern Avatar asked Feb 06 '23 05:02

M.Ern


1 Answers

It could be the following issues :

  1. You forgot to register your View for navigation
  2. You forgot to register a type with the DI container
  3. You have a Null Reference or other Exception being thrown in your View or ViewModel. Note that the Exception could be thrown due to a custom control or other extension methods you are using in your View.
  4. There is an error with .xaml - try commenting out a section of the code
  5. Make sure you actually have a root page in your app.xaml.cs NavigationService.NavigateAsync("/HomePage");
  6. This function might help you find the real reason why its failing if it's failing in App.xaml.cs

    protected override async void OnInitialized()
    {
        try
        {
            TaskScheduler.UnobservedTaskException += (sender, e) => {
                Logger.Log(e.Exception.ToString(), Category.Exception, Priority.High);
            };
            await NavigationService.NavigateAsync("HomePage");
        }
        catch(Exception e)
        {
            Logger.Log(e.ToString(), Category.Exception, Priority.High);
        }
    }
    
like image 170
LeRoy Avatar answered Feb 07 '23 19:02

LeRoy