-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Describe the bug
I'm following the guide at https://docs.microsoft.com/en-us/aspnet/core/blazor/components/prerendering-and-integration?view=aspnetcore-6.0&pivots=server#preserve-prerendered-state to preserve the prerendered component state. However when I try to run the application I get the following error:

To Reproduce
1 -> Create new Blazor Server template
2 -> Add the <preserve-component-state /> below <script src="_framework/blazor.server.js"></script> in _Host.cshtml
3 -> Change the code in FetchDate.razor to the code mentioned in https://docs.microsoft.com/en-us/aspnet/core/blazor/components/prerendering-and-integration?view=aspnetcore-6.0&pivots=server#preserve-prerendered-state.
4 -> Run application
It seems this issue also occurs using the hosted webassembly template but I'm not familiar enough with that approach to be 100% sure of that.
A few more potential issuesI have noticed:
- The prerendered html returns "An unhandled exception has occurred. See browser dev tools for details.", however no error is shown in the dev tools
- It seems like
ApplicationState.OnPersistingis not working because when I add a breakpoint it doesn't seem to be getting hit - https://docs.microsoft.com/en-us/aspnet/core/blazor/components/lifecycle?view=aspnetcore-5.0#stateful-reconnection-after-prerendering-1 seems the approach mentioned here can be replaced by
<preserve-component-state /> - https://docs.microsoft.com/en-us/aspnet/core/blazor/components/prerendering-and-integration?view=aspnetcore-6.0&pivots=webassembly#preserve-prerendered-state does not have a section for the WebAssembly implementation
Further technical details
ASP.NET Core version 6.0.100-preview.7.21379.14
Visual studio community 2022 preview 3.1