I'm trying to write an .NET MAUI Blazor application, that shares the UI with a traditional Blazor application, as can be seen in the BlazorWeather example found at https://github.com/danroth27/BlazorWeather.
My twist on this formula is that I want to be able to use authentication within my application and share as much code as posible. Ideally I'd want to put all aplication logic inside the shared UI (and API that's of course also going to be just one for both Web and MAUI).
I've tried to create a very basic sample Solution so you could see what my issue is. The public repository should be accessible at https://github.com/Dukenware/OneToRuleThemAll
The steps I've followed:
- I've started by creating a Blazor Server with default authentication of type "Individual Accounts".
- Tested that the application runs as expected.
- Created a Razor Class Library project that I've added to the solution.
- Moved all logic from BlazorServer to the RazorClassLibrary project.
- Fixed HTML styling and so on so the application runs as before.
- Added MAUI Blazor project.
- Tested that the MAUI application runs as expected.
- Referenced the RazorClassLibraryProject.
- Tried displaying the UI from RazorClassLibrary by running the RazorClassLibrary.App from MauiBlazor's Main.razor.
- Getting the authentication exception:
GetAuthenticationStateAsync was called before SetAuthenticationState.
at Microsoft.AspNetCore.Components.Server.ServerAuthenticationStateProvider.GetAuthenticationStateAsync()
at Microsoft.AspNetCore.Components.Authorization.CascadingAuthenticationState.OnInitialized()
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
I'd really appretiate if someone could point me to a working templete that I could use to build my application upon. Any feedback is heartily welcome.