Share via

Login flow error

Eduardo Gomez 4,316 Reputation points
2025-11-30T17:02:39.6833333+00:00

So I have the dashboard page and auth in the appshell.xaml.cs I am doing

`       public partial class AppShell : Shell
{
    private readonly IFirebaseAuthClient _auth;
    public AppShell(IFirebaseAuthClient auth)
    {
        InitializeComponent();
        _auth = auth;
        // Register routes
        Routing.RegisterRoute(nameof(DashboardPage), typeof(DashboardPage));
        Routing.RegisterRoute(nameof(AuthenticationPage), typeof(AuthenticationPage));
        Routing.RegisterRoute(nameof(NewProductPage), typeof(NewProductPage));
        Routing.RegisterRoute(nameof(StoresPage), typeof(StoresPage));
        Routing.RegisterRoute(nameof(InventoryPage), typeof(InventoryPage));
        Routing.RegisterRoute(nameof(NoInternetPage), typeof(NoInternetPage));
        Routing.RegisterRoute(nameof(DrawingPage), typeof(DrawingPage));
        Routing.RegisterRoute(nameof(NewStorePage), typeof(NewStorePage));
        // Navigate once Shell is fully ready
        MainThread.BeginInvokeOnMainThread(async () =>
        {
            if (_auth.User == null)
                await GoToAsync($"//{nameof(AuthenticationPage)}");
            else
                await GoToAsync($"//{AppConstants.HOME}");
        });
    }
}

I keep saying

Android.Runtime.JavaProxyThrowable

I asked ChatGPT multiple times bus is always the same

it always tell me that is a timing issue

App.cs

namespace SnapLabel;

public partial class App : Application {

    private readonly AppShell _appShell;
    private readonly IFirebaseAuthClient authClient;
    private readonly IConnectivity _connectivity;

    public App(AppShell appShell, IConnectivity connectivity, IFirebaseAuthClient firebaseAuth) {
        InitializeComponent();

        _appShell = appShell;
        _connectivity = connectivity;
        authClient = firebaseAuth;

        // Subscribe to connectivity changes
        _connectivity.ConnectivityChanged += (_, e) =>
            MainThread.BeginInvokeOnMainThread(async () => await HandleConnectivityAsync(e));
    }

    protected override async void OnStart() {
        if(authClient.User == null)
            await Shell.Current.GoToAsync($"//{nameof(AuthenticationPage)}");
        else
            await Shell.Current.GoToAsync($"//{AppConstants.HOME}");
    }

    protected override Window CreateWindow(IActivationState? activationState) {
        var window = new Window(_appShell);

        // Run initialization after window is created
        MainThread.BeginInvokeOnMainThread(async () => await InitAppAsync());

        return window;
    }

    private async Task InitAppAsync() {

        if(_connectivity.NetworkAccess != NetworkAccess.Internet) {
            if(!_appShell.Navigation.ModalStack.OfType<NoInternetPage>().Any())
                await _appShell.Navigation.PushModalAsync(new NoInternetPage());
        }
    }

    private async Task HandleConnectivityAsync(ConnectivityChangedEventArgs e) {
        bool hasNoInternetModal = _appShell.Navigation.ModalStack.OfType<NoInternetPage>().Any();

        if(e.NetworkAccess != NetworkAccess.Internet) {
            if(!hasNoInternetModal)
                await _appShell.Navigation.PushModalAsync(new NoInternetPage());
        }
        else {
            if(hasNoInternetModal)
                await _appShell.Navigation.PopModalAsync();
        }
    }
}

Developer technologies | .NET | .NET Multi-platform App UI
0 comments No comments

Answer accepted by question author

  1. Jack Dang (WICLOUD CORPORATION) 17,905 Reputation points Microsoft External Staff Moderator
    2025-12-01T06:41:12.5766667+00:00

    Hi @Eduardo Gomez ,

    Thanks for reaching out.

    From the code and description you provided, the Android.Runtime.JavaProxyThrowable might be happening because the app could be attempting navigation too early in the startup process. On Android, MAUI’s UI elements, including Shell and its navigation stack, may not be fully initialized until after the Window is created and the visual tree is ready. Attempting GoToAsync in the constructor of AppShell or in OnStart can sometimes lead to crashes if the Shell isn’t ready to process navigation.

    Here are some points to consider:

    1. Navigation should generally happen after Shell is initialized. The official docs for Shell.GoToAsync explain that navigation is asynchronous and works best once the navigation stack is ready: https://learn.microsoft.com/en-us/dotnet/api/microsoft.maui.controls.shell.gotoasync?view=net-maui-10.0
    2. Routes need to be registered before calling GoToAsync. The Shell navigation documentation shows how to define routes and mentions that navigation assumes routes are already registered: https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/shell/navigation?view=net-maui-10.0
    3. Modal pages on startup may introduce additional timing considerations. The Shell pages documentation explains modal presentation and navigation stack behavior: https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/shell/pages?view=net-maui-9.0

    Possible guidance:

    • Consider deferring navigation until the Shell is fully created, for example inside CreateWindow after the window is initialized or in OnAppearing of a startup page.
    • Ensure that all routes are registered before calling GoToAsync.
    • Await all GoToAsync calls and avoid starting multiple navigation operations simultaneously.

    Following these patterns might help reduce the chance of crashes on Android related to early navigation, though actual results can vary depending on timing and platform behavior.

    Hope this helps! If my answer was helpful - kindly follow the instructions here so others with the same problem can benefit as well.

    Was this answer helpful?

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.