Closed
Description
Use AddRazorRuntimeCompilation
in Blazor Server will cause an exception.
InvalidOperationException: Setting the compiled descriptor on a compiled descriptor is not allowed.
Environment:
SDK 6.0.100-preview.6.21355.2
Reproduce:
> dotnet new blazorserver -o BlazorApp
> cd BlazorApp
> dotnet add package Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation --version 6.0.0-preview.6.21355.2
Use AddRazorRuntimeCompilation
in Startup class.
- services.AddRazorPages();
+ services.AddRazorPages().AddRazorRuntimeCompilation();
Run the app:
System.InvalidOperationException: Setting the compiled descriptor on a compiled descriptor is not allowed.
at Microsoft.AspNetCore.Mvc.RazorPages.CompiledPageActionDescriptor.set_CompiledPageDescriptor(CompiledPageActionDescriptor value) in Microsoft.AspNetCore.Mvc.RazorPages.dll:token 0x60000dc+0xa
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.CompiledPageActionDescriptorFactory.CreateCompiledDescriptor(PageActionDescriptor actionDescriptor, CompiledViewDescriptor viewDescriptor) in Microsoft.AspNetCore.Mvc.RazorPages.dll:token 0x600024a+0x79
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.DefaultPageLoader.LoadAsyncCore(PageActionDescriptor actionDescriptor, EndpointMetadataCollection endpointMetadata) in Microsoft.AspNetCore.Mvc.RazorPages.dll:token 0x6000267+0x9c
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageLoaderMatcherPolicy.ApplyAsyncAwaited(CandidateSet candidates, Task`1 actionDescriptorTask, Int32 index) in Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.dll:token 0x6000019+0x6c
at Microsoft.AspNetCore.Routing.Matching.DfaMatcher.SelectEndpointWithPoliciesAsync(HttpContext httpContext, IEndpointSelectorPolicy[] policies, CandidateSet candidateSet) in Microsoft.AspNetCore.Routing.dll:token 0x600033a+0x90
at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.<Invoke>g__AwaitMatch|8_1(EndpointRoutingMiddleware middleware, HttpContext httpContext, Task matchTask) in Microsoft.AspNetCore.Routing.dll:token 0x60000ba+0x65
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context) in Microsoft.AspNetCore.Diagnostics.dll:token 0x60000aa+0x82
The actionDescriptor
here may be is CompiledPageActionDescriptor
.
https://github.com/dotnet/aspnetcore/blob/v6.0.0-preview.6.21355.2/src/Mvc/Mvc.RazorPages/src/Infrastructure/CompiledPageActionDescriptorFactory.cs#L52
https://github.com/dotnet/aspnetcore/blob/v6.0.0-preview.6.21355.2/src/Mvc/Mvc.RazorPages/src/CompiledPageActionDescriptor.cs#L75