File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
src/Components/WebAssembly/Server/src Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 11// Licensed to the .NET Foundation under one or more agreements.
22// The .NET Foundation licenses this file to you under the MIT license.
33
4+ using System . Reflection ;
45using Microsoft . AspNetCore . Components ;
56using Microsoft . AspNetCore . Components . Authorization ;
67using Microsoft . AspNetCore . Components . Endpoints . Infrastructure ;
@@ -25,6 +26,15 @@ public static IRazorComponentsBuilder AddInteractiveWebAssemblyComponents(this I
2526
2627 builder . Services . TryAddEnumerable ( ServiceDescriptor . Singleton < RenderModeEndpointProvider , WebAssemblyEndpointProvider > ( ) ) ;
2728
29+ // Try register LazyAssemblyLoader to prevent crashes during prerendering.
30+ // TODO: Remove this once LazyAssemblyLoader is deprecated.
31+ var lazyAssemblyLoaderType = GetLazyAssemblyLoaderType ( ) ;
32+
33+ if ( lazyAssemblyLoaderType != null )
34+ {
35+ builder . Services . AddScoped ( lazyAssemblyLoaderType ) ;
36+ }
37+
2838 return builder ;
2939 }
3040
@@ -46,4 +56,17 @@ public static IRazorComponentsBuilder AddAuthenticationStateSerialization(this I
4656
4757 return builder ;
4858 }
59+
60+ private static Type ? GetLazyAssemblyLoaderType ( )
61+ {
62+ try
63+ {
64+ var assembly = Assembly . Load ( "Microsoft.AspNetCore.Components.WebAssembly" ) ;
65+ return assembly . GetType ( "Microsoft.AspNetCore.Components.WebAssembly.Services.LazyAssemblyLoader" , throwOnError : false ) ;
66+ }
67+ catch
68+ {
69+ return null ;
70+ }
71+ }
4972}
You can’t perform that action at this time.
0 commit comments