question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PushModalAsync on Android not working in latest Visual Studio Update

See original GitHub issue

Description

Navigation.PushModalAsync appears to be broken on Android in the newest version of MAUI in Visual Studio Professional 2022 Preview 17.3.0 Preview 2

Steps to Reproduce

  1. Create a new .Net MAUI Project
  2. Create a new MAUI Content Page
  3. Create a modal to be opened on startup: Navigation.PushModalAsync(new ContentPage())
  4. Run in it in the Android Emulator

Version with bug

6.0.400 (current)

Last version that worked well

6.0.312

Affected platforms

Android

Affected platform versions

net6.0-android minimum 21.0

Did you find any workaround?

No

Relevant log output

System.InvalidOperationException: 'Current Root View cannot be null'

WORKAROUND

using Microsoft.Maui.Handlers;

namespace MauiApp32;

public partial class App : Application
{
    public App()
    {
        InitializeComponent();

        MainPage = new AppShell();
        WindowHandler.Mapper.ModifyMapping(nameof(IWindow.Content), OnWorkaround);

    }

    private void OnWorkaround(IWindowHandler arg1, IWindow arg2, Action<IElementHandler, IElement> arg3)
    {
        WindowHandler.MapContent(arg1, arg2);
    }
}

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
PureWeencommented, Jun 16, 2022

@Wandtket @egvijayanand @dm-pr

I posted a workaround on the description that should fix your issue for now

1reaction
egvijayanandcommented, Jun 16, 2022

It worked. Handler makes life easy.

Just making it simple:

WindowHandler.Mapper.ModifyMapping(nameof(IWindow.Content), (handler, window, _) => WindowHandler.MapContent(handler, window));
Read more comments on GitHub >

github_iconTop Results From Across the Web

PushAsync is not supported globally on Android, please ...
Verify that the previous page is not using a PushModalAsync. If later you use a PushAsync, you will have the error "PushAsync is...
Read more >
PushModalAsync doesn't work in Android
If I call PushModalAsync in Android I have two problems: 1) When the page calls PopModalAsync there is no handler activated in the...
Read more >
Navigation.PushModalAsync() does nothing - Microsoft Q&A
Hello, I've a Shell-based XF app and upgraded recently from 4.6.0.847 to (currently) 5.0.0.1931. On some page, I handle a tap event like ......
Read more >
Xamarin Android application is not able to connect to MVC ...
The Issue I am facing is that the Android application is throwing an exception while connecting with MVC core web API. And here...
Read more >
Xamarin Forms Navigation and physical keyboard
I was trying to solve another problem with PushModalAsync and the physical keyboard. When you are pressing the Tab key on the modal...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found