Lazy load not trimmable assembly with (or without) AOT

111 Views Asked by At

The page https://learn.microsoft.com/en-us/aspnet/core/blazor/webassembly-lazy-load-assemblies?view=aspnetcore-8.0#code-try-0 uses the {FILE EXTENSION} placeholder, while in https://learn.microsoft.com/en-us/aspnet/core/blazor/webassembly-lazy-load-assemblies?view=aspnetcore-8.0#file-extension-placeholder-file-extension-for-assembly-files it is stated, that this must be wasm. However, the build fails if the extension provided there is not dll stating that it can't find the wasm file. That is correct, as there is not wasm at this time (AOT or not).

<PropertyGroup>
  <RunAOTCompilation>true</RunAOTCompilation> 
</PropertyGroup>
...
<ItemGroup>
  <TrimmerRootAssembly Include="Blazicons.MaterialDesignIcons" />
  <BlazorWebAssemblyLazyLoad Include="Blazicons.MaterialDesignIcons.wasm" />
</ItemGroup>

results in build error during publish:

error BLAZORSDK1001: Unable to find 'Blazicons.MaterialDesignIcons.wasm' to be lazy loaded later. Confirm that project or package references are included and the reference is used in the project. 8>Done building project "WasmClient.csproj" -- FAILED.

Using .dll instead

<ItemGroup>
  <TrimmerRootAssembly Include="Blazicons.MaterialDesignIcons" />
  <BlazorWebAssemblyLazyLoad Include="Blazicons.MaterialDesignIcons.dll" />
</ItemGroup>

results in a successful build. So far so good.

However, it will result in error during run. https://learn.microsoft.com/en-us/aspnet/core/blazor/webassembly-lazy-load-assemblies?view=aspnetcore-8.0#try-code-1 uses the same placeholder. Using dll fails here, with AOT as there is only wasm at hand by then. Using wasm here also fails with:

Error: Blazicons.MaterialDesignIcons.wasm must be marked with 'BlazorWebAssemblyLazyLoad' item group in your project file to allow lazy-loading.

System.Reflection.TargetInvocationException: Arg_TargetInvocationException ---> System.IO.FileNotFoundException: Could not load file or assembly 'Blazicons.MaterialDesignIcons, Version=1.4.14.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.

...because dll was used in the project file. So they look to be mutually exclusive scenarios.

Trying without AOT, the dll is trimmed during publishing despite the TrimmerRootAssembly setting. Which results in an integrity check error in the browser. The dll is intact, the compressed versions however are trimmed (I have checked, they really are). Which is weird on its own. The compressed+trimmed version is served, but the checksum seems to be the wrong one anyway.

Failed to find a valid digest in the 'integrity' attribute for resource 'https://.../_framework/Blazicons.MaterialDesignIcons.dll' with computed SHA-256 integrity 'gMXbZ3OfWdujY73B/l1KFNoubyP8nqgEYJ/OZjVnvaM='. The resource has been blocked.

enter image description here

Note: removing TrimmerRootAssembly makes this error go away, and makes the sizes in sync:

enter image description here

I am quite confused, as I am seeing myself doing everything by the book :( But I am stuck at the very first step as the wasm extension results in a failed build right at the beginning.

TL;DR; How can I mark an assembly not to be trimmed and load it lazily? AOT is a "nice to have" for now.

0

There are 0 best solutions below