Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] MAUI Blazor - Router AppAssembly could not find pages if assembly is different #3258

Closed
sencagri opened this issue Nov 4, 2021 · 8 comments
Labels
area-blazor Blazor Hybrid / Desktop, BlazorWebView t/bug Something isn't working
Projects

Comments

@sencagri
Copy link

sencagri commented Nov 4, 2021

Description

I am building a blazor project which has a common razor library. WASM and Blazor server uses same project to serve pages and components. I have added a new MAUI Blazor project and referenced the library. Project builds and runs but Router couldn't find the pages. It just show a white blank screen. I am adding a sample project for reproducing.

Expected Behavior

It should run like Blazor Server and Blazor WASM.

Actual Behavior

Router can find MainLayout but cannot find the actual page.

Screenshots

MAUI Blazor - Not Working Blank Screen

MAUI Blazor - Not Working Blank Screen

Blazor WASM - Working

Blazor WASM - Working

Blazor Server - Working

Blazor Server - Working

What I have tried

image

Reproduction Link

BlazorSharedProject.zip reproducing project

@sencagri sencagri added the t/bug Something isn't working label Nov 4, 2021
@jsuarezruiz jsuarezruiz added the area-blazor Blazor Hybrid / Desktop, BlazorWebView label Nov 4, 2021
@jsuarezruiz jsuarezruiz added this to New in Triage via automation Nov 4, 2021
@rogihee
Copy link
Contributor

rogihee commented Nov 4, 2021

You need to tell the Router that there are additional assemblies to scan for routes by setting the "AdditionalAssemblies" property, so something like:

AdditionalAssemblies="new[] { typeof(BigTextComponent).Assembly }" 

@sencagri
Copy link
Author

sencagri commented Nov 5, 2021

I already tried that both with changing AppAssembly and adding my component assembly to AdditionalAssemblies. It didn't work.

image

@Eilon
Copy link
Member

Eilon commented Dec 7, 2021

I just tried this with AdditionalAssemblies and it worked fine.

In my MAUI app project I have Main.razor with exactly this content:

<Router
    AppAssembly="@GetType().Assembly"
    PreferExactMatches="true"
    AdditionalAssemblies="new[]{typeof(MauiRazorClassLibrarySample.Component2).Assembly}"> @* <------- ADD THIS PROPERTY *@
    <Found Context="routeData">
        <RouteView RouteData="@routeData" />
    </Found>
    <NotFound>
        <h1>Not found</h1>
        <p>Sorry, there's nothing here.</p>
    </NotFound>
</Router>

And in some page in the main app I have this navigation link:

<a href="/page1">Page1</a>

And in my Razor Class Library (RCL) I have a file Component2.razor with exactly these contents:

@page "/page1"

<h3>Component2</h3>

@code {

}

And when I click the link, it correctly loads the page1 page defined in the RCL's Component2.razor file.

@sencagri
Copy link
Author

sencagri commented Dec 8, 2021

It looks same as mine. But I will try it again asap.

@Eilon
Copy link
Member

Eilon commented Dec 8, 2021

I think I found the difference. In your repro app the file BlazorShared.Native\Main.razor has the app assembly also listed as an AdditionalAssembly:

AdditionalAssemblies="new[]{GetType().Assembly, typeof(BlazorShared.Docs.Pages.Index).Assembly}">

If you change it to just this;

AdditionalAssemblies="new[]{typeof(BlazorShared.Docs.Pages.Index).Assembly}">

Then it should work.

@Eilon
Copy link
Member

Eilon commented Dec 8, 2021

BTW there is actually a hidden exception that says something about a duplicate route, which makes sense, because the main assembly has everything duplicated, but unfortunately that hidden exception just makes Blazor fail to load.

So I think there are two unrelated bugs here:

  1. Blazor should possibly have a specific error saying that an assembly is duplicated, or just allow it (by ignoring the duplicate)
  2. The duplicate route error should be more visible to the user somehow

@sencagri
Copy link
Author

sencagri commented Dec 8, 2021 via email

@Eilon
Copy link
Member

Eilon commented Dec 8, 2021

I filed these issues:

But I think the specific issue in this bug is resolved, so I'm closing this out. Very interesting issue 😄

@Eilon Eilon closed this as completed Dec 8, 2021
@hartez hartez moved this from New to Done in Triage Dec 27, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Feb 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Blazor Hybrid / Desktop, BlazorWebView t/bug Something isn't working
Projects
No open projects
Development

No branches or pull requests

4 participants