MvvmCross.Forms cannot replace app's MainPage

Created on 1 Feb 2018  路  6Comments  路  Source: MvvmCross/MvvmCross



Steps to reproduce :scroll:

  1. Create an app with root page that is content or navigation page. Add additional page to project with type of MvxTabbedPage and attribute [MvxTabbedPagePresentation(Position = TabbedPosition.Root, WrapInNavigationPage = false)]
  2. When root view is loaded try navigate to tabbed page using IMvxNavigatingService.Navigate and await the call, app will crash with exception "Cannot replace MainPage".

  3. The reason of the crash is that MvxFormsApplicationDelegate method FinishedLaunching is not calling base.FinishedLaunching, so FormsApplicationDelegate private field "_window" is not initialised, and app crashes at method UpdateMainPage of FormsApplicationDelegate.

Expected behavior :thinking:

MainPage gets replaced

Actual behavior :bug:

App crash

Configuration :wrench:

Version: 5.6.x

Platform:

  • [x] :iphone: iOS
  • [ ] :robot: Android
  • [ ] :checkered_flag: WPF
  • [ ] :earth_americas: UWP
  • [ ] :apple: MacOS
  • [ ] :tv: tvOS
  • [x] :monkey: Xamarin.Forms
forms needs-investigation bug

Most helpful comment

This is fixed in the playground.

All 6 comments

Facing the same issue. Any fix ?

I'm using workaround for now.
private void InitializeInternalWindow(UIWindow window) { var windowField = typeof(FormsApplicationDelegate).GetField("_window", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); windowField.SetValue(this, window); }
Call this method in FinishedLaunching after you created UIWindow, and pass it there.

@vkonst86 - Thanks. Your workaround works like charm.

@vkonst86 are you able to reproduce this in the playground sample? If so, can you submit a PR with your changes showing how to reproduce the issue

This is fixed in the playground.

@martijn00 can you add the reference source code over here?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

beylkhanovdamir picture beylkhanovdamir  路  4Comments

RonakPatel21 picture RonakPatel21  路  4Comments

a7ex picture a7ex  路  3Comments

ssepulveda picture ssepulveda  路  5Comments

prin53 picture prin53  路  4Comments