Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 21 additions & 31 deletions knowledge-base/common-lazy-load-assemblies-wasm.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ res_type: kb
<td>Product</td>
<td>UI for Blazor</td>
</tr>
<tr>
<td>Version</td>
<td>2.19.0 and above</td>
</tr>
<tr>
<td>.NET version</td>
<td>5 and above</td>
</tr>
</tbody>
</table>

Expand All @@ -42,53 +34,51 @@ All general guidance from the [Microsoft documentation](https://learn.microsoft.
````XML.skip-repl
<ItemGroup>
<!-- Components and data binding -->
<BlazorWebAssemblyLazyLoad Include="Telerik.Blazor.dll" />
<BlazorWebAssemblyLazyLoad Include="Telerik.DataSource.dll" />
<BlazorWebAssemblyLazyLoad Include="System.Data.Common.dll" />
<BlazorWebAssemblyLazyLoad Include="System.Linq.Queryable.dll" />
<BlazorWebAssemblyLazyLoad Include="Telerik.Blazor.wasm" />
<BlazorWebAssemblyLazyLoad Include="Telerik.DataSource.wasm" />
<BlazorWebAssemblyLazyLoad Include="System.Data.Common.wasm" />
<BlazorWebAssemblyLazyLoad Include="System.Linq.Queryable.wasm" />
<!-- Icons -->
<BlazorWebAssemblyLazyLoad Include="Telerik.SvgIcons.dll" />
<BlazorWebAssemblyLazyLoad Include="Telerik.FontIcons.dll" />
<BlazorWebAssemblyLazyLoad Include="Telerik.SvgIcons.wasm" />
<BlazorWebAssemblyLazyLoad Include="Telerik.FontIcons.wasm" />
<!-- PivotGrid -->
<BlazorWebAssemblyLazyLoad Include="Telerik.Pivot.Core.dll" />
<BlazorWebAssemblyLazyLoad Include="Telerik.Pivot.DataProviders.Xmla.dll" />
<BlazorWebAssemblyLazyLoad Include="Telerik.Pivot.Core.wasm" />
<BlazorWebAssemblyLazyLoad Include="Telerik.Pivot.DataProviders.Xmla.wasm" />
<!-- Scheduler -->
<BlazorWebAssemblyLazyLoad Include="Telerik.Recurrence.dll" />
<BlazorWebAssemblyLazyLoad Include="Telerik.Recurrence.wasm" />
<!-- Excel export -->
<BlazorWebAssemblyLazyLoad Include="Telerik.Documents.SpreadsheetStreaming.dll" />
<BlazorWebAssemblyLazyLoad Include="Telerik.Zip.dll" />
<BlazorWebAssemblyLazyLoad Include="Telerik.Documents.SpreadsheetStreaming.wasm" />
<BlazorWebAssemblyLazyLoad Include="Telerik.Zip.wasm" />
<!-- PDF export (only for version 8.0.0 and above) -->
<BlazorWebAssemblyLazyLoad Include="Telerik.Documents.Spreadsheet.FormatProviders.Pdf.wasm" />
<!-- Licensing (only for version 8.0.0 and above ) -->
<BlazorWebAssemblyLazyLoad Include="Telerik.Licensing.Runtime.wasm" />
</ItemGroup>
````

* The assembly requirements depend on component usage, and not on feature usage. For example, both icon assemblies are always required, as our components render icons internally and must be aware of both types of icons. The assemblies, which are related to Excel export, are always required when using a Grid. `Telerik.Recurrence.dll` is required only when using the Scheduler.
* The assembly requirements depend on component usage, and not on feature usage. For example, both icon assemblies are always required, as our components render icons internally and must be aware of both types of icons. The assemblies, which are related to Excel and PDF export, are always required when using a Grid. `Telerik.Recurrence.wasm` is required only when using the Scheduler.
* Move the [`<TelerikRootComponent>`](slug:rootcomponent-overview) to a layout that is used only on pages that have the Telerik assemblies loaded.
* Lazy loading of assemblies does not support dynamic service injection. As a result, remove the Telerik service registration (`builder.Services.AddTelerikBlazor();`) from `Program.cs`. If you are using [localization for the Telerik Blazor components](slug:globalization-localization), define the the localization service for the Telerik components with the `Localizer` parameter of the `<TelerikRootComponent>`. The key thing is to instantiate the localization service inline. It cannot be injected as a variable from the `@code { }` block, because that will throw runtime errors.


````RAZOR.skip-repl

@using LazyLoadTelerikComponents.Shared.Services


<TelerikRootComponent Localizer="@( new SampleResxLocalizer() )">

...

</TelerikRootComponent>

````

Overall, the lazy loading of assemblies at the correct time is a responsibility of the application. If an assembly is not loaded when required, the app will throw `System.IO.FileNotFoundException: Could not load file or assembly ...`. The loading code is in the `OnNavigateAsync` event handler of the `<Router>`. You can also define an optional loading screen inside the `<Router>` with a `<Navigating>` tag.

### .NET 8 and 9 Specifics
### .NET Specifics

The following tips apply only to .NET 8 and 9 WebAssembly apps:
The following tips apply to WebAssembly apps that use specific .NET versions:

* Use `.wasm` instead of `.dll` in the `.csproj` file and the `OnNavigateAsync` event handler.
* [Register the lazy loader service manually](https://github.com/dotnet/aspnetcore/issues/51966) in the "server" `Program.cs`. Otherwise, you may get a `InvalidOperationException: Cannot provide a value for property 'AssemblyLoader' on type '...Routes'. There is no registered service of type 'Microsoft.AspNetCore.Components.WebAssembly.Services.LazyAssemblyLoader'.`
* (.NET 7 and below) Use `.dll` instead of `.wasm` in the `.csproj` file and the `OnNavigateAsync` event handler.
* (.NET 8 and above) [Register the lazy loader service manually](https://github.com/dotnet/aspnetcore/issues/51966) in the "server" `Program.cs`. Otherwise, you may get a `InvalidOperationException: Cannot provide a value for property 'AssemblyLoader' on type '...Routes'. There is no registered service of type 'Microsoft.AspNetCore.Components.WebAssembly.Services.LazyAssemblyLoader'.`

````C#.skip-repl
using Microsoft.AspNetCore.Components.WebAssembly.Services;

builder.Services.AddScoped(typeof(LazyAssemblyLoader));
````

Expand Down