dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.28k stars 1.76k forks source link

MAUI-Blazor Exception #1482

Closed MRakesh closed 3 years ago

MRakesh commented 3 years ago

Hi Daniel Roth, The below code is working in blazor hosted wasm

public class ParentComponentBase : ComponentBase
  { 
    [Inject] protected NavigationManager _navigation { get; set; }
    [Inject] protected IJSRuntime _jsRuntime { get; set; }
}

 public partial class Index : ParentComponentBase
 {
 }

and in Index.razor file

@inherits ParentComponentBase

but the same above code is not working in MAUI-Blazor, getting unhandled error in android emulator.

ghost commented 3 years ago

Thanks for contacting us.

We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

danroth27 commented 3 years ago

@MRakesh Thanks for reporting this issue. What is the specific error that you get on Android?

MRakesh commented 3 years ago

I am not sure how to see the error in emulator and the debugger is not working for Maui-Blazor app in my VS but at the bottom that says unhandled exception Reload

MRakesh commented 3 years ago

I am not sure how to see the error in emulator and the debugger is not working for Maui-Blazor app in my VS but at the bottom that says unhandled exception Reload

rabberbock commented 3 years ago

I am also running into a similar issue as well. Wasm works well, but on Maui I get the following chromium error in the android device logs:

Time    Device Name Type    PID Tag Message
07-02 11:27:14.759  pixel_2_pie_9_0_-_api_28    Info    26807   chromium    [INFO:CONSOLE(1)] "Object reference not set to an instance of an object.
   at Microsoft.AspNetCore.Components.Routing.Router.Refresh(Boolean isNavigationIntercepted)
   at Microsoft.AspNetCore.Components.Routing.Router.SetParametersAsync(ParameterView parameters)", source: https://0.0.0.0/_framework/blazor.webview.js (1)

FYI, I am using authentication in my application and am trying to implement a custom authentication state provider that uses a refresh token stored on the android device (retrieved using WebAuthenticator Maui Essentials and then calling the token endpoint which works great!) to get the access token. In my Wasm application I am using the Blazor Wasm out of the box oidc services. So slightly different workflow.

Will try to put together a repro later. Thanks!

Eilon commented 3 years ago

I am not able to reproduce this.

This is my index.razor:

@inherits ParentComponentBase
@page "/"

<h1>This is the count: @count</h1>
<button @onclick="Increment">Increment</button>

<ul>
    <li>1: @_navigation.BaseUri</li>
    <li>2: @_jsRuntime.GetType().FullName</li>
</ul>

@code {

    int count = 0;

    void Increment()
    {

        count++;
    }
}

And this is index.razor.cs:

using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;

namespace Maui.Controls.Sample.SingleProject.Pages
{
    public class ParentComponentBase : ComponentBase
    {
        [Inject] protected NavigationManager _navigation { get; set; }
        [Inject] protected IJSRuntime _jsRuntime { get; set; }
    }

    public partial class Index : ParentComponentBase
    {
    }
}

And here it is running on Android:

image

Eilon commented 3 years ago

I am seeing this exception now but in a very different scenario.

Eilon commented 3 years ago

Ah, it looks like in my case there's an ambiguous route:

System.InvalidOperationException: 'The following routes are ambiguous:
'/' in 'Maui.Controls.Sample.Pages.Others.Index'
'/' in 'Maui.Controls.Sample.Pages.Index'
'

And it's bubbling up as a super weird exception.

Eilon commented 3 years ago

Once I fixed the ambiguous route, the error completely went away.

And as far as that error showing up to begin with, I think that's this Blazor bug: https://github.com/dotnet/aspnetcore/issues/32411

So I'm not aware of any specific issue in Blazor Desktop.