-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Try register LazyAssemblyLoader to DI in AddInteractiveWebAssemblyCom… #61719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try register LazyAssemblyLoader to DI in AddInteractiveWebAssemblyCom… #61719
Conversation
This is an alternative solution to #61703. Only one of these should be merged. |
please consider backport |
…semblyLoader registration
@@ -25,6 +30,15 @@ public static IRazorComponentsBuilder AddInteractiveWebAssemblyComponents(this I | |||
|
|||
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<RenderModeEndpointProvider, WebAssemblyEndpointProvider>()); | |||
|
|||
// Try register LazyAssemblyLoader to prevent crashes during prerendering. | |||
// TODO: Remove this once LazyAssemblyLoader is no longer used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the TODO please
|
||
private static void AssertServerProjectCanUseLazyAssemblyLoader(Project project) | ||
{ | ||
var assemblyName = "Microsoft.AspNetCore.Components.WebAssembly.dll"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also check that the class is in the dll
// This assert is here to check that the assembly containing LazyAssemblyLoader is actually present in a standard app | ||
// created from the Blazor Web template. | ||
// See https://github.com/dotnet/aspnetcore/issues/51966. | ||
// TODO: Remove this when LazyAssemblyLoader is no longer being used, or the dependency graph changes so reflection is no longer needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove todo
It turned out the much simpler fix was actually possible (#61822). I erroneously thought it required a project configuration change that we did not want to do (e.g. adding the assembly into the Shared Framework). |
Changes
LazyAssemblyLoader
inAddInteractiveWebAssemblyComponents
.Description
We want to register
LazyAssemblyLoader
inAddInteractiveWebAssemblyComponents
in order to prevent the confusing situation where a component that injectsLazyAssemblyLoader
works in the WebAssembly client but crashes during prerendering. (Note that it works when the wasm client takes over becauseWebAssemblyHostBuilder.CreateDefault
registersLazyAssemblyLoader
.)However, this could not be done as is without adding a problematic reference between projects. To avoid this, the implementation uses reflection to try to load the
Microsoft.AspNetCore.Components.WebAssembly
assembly and get the type. If the assembly or the type cannot be found, no error is thrown.