You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: knowledge-base/common-lazy-load-assemblies-wasm.md
+73-5Lines changed: 73 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,17 +4,85 @@ description: How to use the lazy assembly loading feature of Blazor with the Tel
4
4
type: how-to
5
5
page_title: Telerik Blazor Components and WebAssembly Lazy Load of Assemblies
6
6
slug: common-kb-lazy-load-assemblies-wasm
7
-
position:
8
-
tags:
7
+
position:
8
+
tags:
9
+
ticketid: 1628239, 1633572
9
10
res_type: kb
10
11
---
11
12
13
+
## Environment
12
14
13
-
## Description
15
+
<table>
16
+
<tbody>
17
+
<tr>
18
+
<td>UI for Blazor version</td>
19
+
<td>2.19.0 and above</td>
20
+
</tr>
21
+
<tr>
22
+
<td>.NET version</td>
23
+
<td>5 and above</td>
24
+
</tr>
25
+
</tbody>
26
+
</table>
14
27
15
-
How to use the lazy assembly loading feature of Blazor with the Telerik components?
28
+
## Description
16
29
30
+
How to use the [lazy assembly loading feature of Blazor WebAssembly apps](https://learn.microsoft.com/en-us/aspnet/core/blazor/webassembly-lazy-load-assemblies) with the Telerik Blazor components?
17
31
18
32
## Solution
19
33
20
-
An example is available in the following project: [https://github.com/telerik/blazor-ui/tree/master/common/lazy-load-assemblies-wasm](https://github.com/telerik/blazor-ui/tree/master/common/lazy-load-assemblies-wasm).
34
+
All general guidance from the [Microsoft documentation](https://learn.microsoft.com/en-us/aspnet/core/blazor/webassembly-lazy-load-assemblies) applies. The Telerik-related specifics are:
35
+
36
+
* List the following assemblies in the "client" `.csproj` file to be lazy loaded.
* 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.
60
+
* Move the `<TelerikRootComponent>` to a layout that is used only on pages that have the Telerik assemblies loaded.
61
+
* 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.
62
+
63
+
````
64
+
@using LazyLoadTelerikComponents.Shared.Services
65
+
66
+
<TelerikRootComponent Localizer="@( new SampleResxLocalizer() )">
67
+
...
68
+
</TelerikRootComponent>
69
+
````
70
+
71
+
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.
72
+
73
+
### .NET 8 Specifics
74
+
75
+
The following tips apply to .NET 8 WebAssembly apps only:
76
+
77
+
* Use `.wasm` instead of `.dll` in the `.csproj` file and the `OnNavigateAsync` event handler.
78
+
* [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'.`
79
+
80
+
````
81
+
using Microsoft.AspNetCore.Components.WebAssembly.Services;
An sample project is available in GitHub: [Lazy load Telerik Blazor assemblies](https://github.com/telerik/blazor-ui/tree/master/common/lazy-load-assemblies-wasm).
0 commit comments