[Blazor] Maui windows apps can't find _framework/blazor.modules.json
javiercn opened this issue · 11 comments
For some reason the apps fail to find the file and as a result initializers don't load. It works fine in other platforms like Android
This isn't working for me on Android or Windows MAUI currently (unable to test iOS). Neither beforeStart
or afterStarted
initializers are working (as described here). Using latest net7.0
workloads:
> dotnet workload list
Installed Workload Id Manifest Version Installation Source
--------------------------------------------------------------------------------
android 33.0.46/7.0.100 SDK 7.0.200, VS 17.5.33530.505
ios 16.2.2054/7.0.100 SDK 7.0.200, VS 17.5.33530.505
maccatalyst 16.2.2054/7.0.100 SDK 7.0.200, VS 17.5.33530.505
maui-android 7.0.81/7.0.100 VS 17.5.33530.505
wasm-tools 7.0.5/7.0.100 VS 17.5.33530.505
maui-windows 7.0.81/7.0.100 VS 17.5.33530.505
maui-maccatalyst 7.0.81/7.0.100 VS 17.5.33530.505
maui-ios 7.0.81/7.0.100 VS 17.5.33530.505
Note that I tried this both with putting the {ASSEMBLY NAME}.lib.module.js
file under the MAUI project wwwroot
folder, as well as under an RCL's wwwroot
folder, but same results either way. I do see that the {MAUI_PROJECT}.modules.json
file is being created in the output wwwroot
folder (which also means I'm naming those files correctly).
Ultimately, after stepping through the _framework/blazor.webview.js
for a bit, what I found was that these initializers are supposed to be loaded via the importInitializersAsync
JS method, which uses the _framework/blazor.modules.json
to determine which JS files needs to be run as initializers. On Android, using CDT and looking at the network tab, I can see that the _framework/blazor.modules.json
file is returned as an empty array (same for the Windows app). Both network requests have a status code of 200.
Just wanted to add my experiences, as well as inquire if there are any plausible workarounds? Really what I'm after is the ability to trigger a JS specific workload BEFORE Blazor.Start()
is called, or at least before any of the .NET ecosystem is loaded. However, when using the MAUI BlazorWebView
, Blazor.Start()
is called automatically therefore the autostart=false
mechanism can't be used as in WASM.
Thanks for contacting us.
We're moving this issue to the .NET 8 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.
@mkArtakMSFT, @javiercn We are running into this when using the Blazor Fluent UI library in A Blazor Hybrid project (see microsoft/fluentui-blazor#404 (comment)). Any indication on if/when/how this is solved? And are there known workarounds (besides building your own Microsoft.AspNetCore.Components.WebView :))?
@mkArtakMSFT, @javiercn, one of our contributors has created a nice workaround for this. See https://github.com/microsoft/fluentui-blazor#tempory-workaround-for-maui-issues for the details.
is this PR relevant?
dotnet/aspnetcore#48594
Issue also exists with RCL component hosted in BlazorWebView in Windows Forms and Wpf projects. Workaround mentioned by @vnbaaij is required.
Is this problem fixed in .NET 8?
Do Blazor JS module initializers work in NET 8 in Blazor Hybrid? Is loading file wwwroot/{AppName}.lib.module.js in Blazor hybrid / BlazorWebView fixed?
Verified this issue with Visual Studio Enterprise 17.9.0 Preview 2. Can repro this issue.
@javiercn Hi when is this fix released? And when it is released, do the old projects that use the workaround need to remove it? We have tons of MAUI projects that is currently using the initializersLoader.webview.js
workaround
This indeed does look to be fixed in .NET9. With .NET9, you should not use the workaround https://github.com/microsoft/fluentui-blazor?tab=readme-ov-file#temporary-workaround-for-mauiwpfwindows-forms-issues, for Blazor Fluent UI, and in fact things won't work if you do since now the modules file is named _framework/blazor.modules.json
and the workaround has it look for <app-name>.modules.json
, which is no longer generated.