assemblylazy-loadingblazor-webassemblyrazor-class-library

Unable to find 'Software1.dll;Software2.dll' to be lazy loaded later. Confirm that project or package references are included and the reference is u


In a webassembly project I created two Razor Class Libraries Software1 and Software2 and added a reference to both in the main client app.

I also added these to my client's Project file:

<ItemGroup>
  <BlazorWebAssemblyLazyLoad Include="Software1.dll"></BlazorWebAssemblyLazyLoad>
  <BlazorWebAssemblyLazyLoad Include="Software2.dll"></BlazorWebAssemblyLazyLoad>
</ItemGroup>

But when I build the project fails wi message:

 Error  BLAZORSDK1001   Unable to find 'Software1.dll;Software2.dll' to be lazy loaded 
later. Confirm that project or package references are included and the reference is used in 
the project.    OTS.UI.Client   C:\Users\..\.nuget\packages\microsoft.net.sdk.webassembly.pack\8.0.0\build
\Microsoft.NET.Sdk.WebAssembly.Browser.targets  372 

When I remove the <ItemGroup>s, Rebuild is successfull and Software1.dll and Software2.dll are there in the bin folder but when <ItemGroup> is present buld fails and bin folder's .net8 folder is empty. How to correct this?


Solution

  • In .NET 8 there is a change in how managed dlls are delivered to the browser. Serving .dll files was causing problems with some antiviruses. We changed the default extension (and inner format) to .wasm and blazor lazy loading needs to change the file extension .

    Please use these two line in the CSProj file.

    <ItemGroup>
      <BlazorWebAssemblyLazyLoad Include="Software1.wasm"></BlazorWebAssemblyLazyLoad>
      <BlazorWebAssemblyLazyLoad Include="Software2.wasm"></BlazorWebAssemblyLazyLoad>
    </ItemGroup>
    

    You can find the link here . https://github.com/dotnet/runtime/issues/92965