-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Visual Studio 2019 16.6.1
.Net Core 3.1.4Using ServerPrerendered the .razor component is initialized twice. First time correctly, the second time incorrectly.
I have the following folder layout:
/Pages/Test/
./RazorShapeComponent.razor
./ShapeContainer.cs
./ShapeBase.cs
./ShapeTriangle.cs/Pages/
./ShapeTest.cshtml
./ShapeTest.cshtml.csWhere:
ShapeTriangle extends ShapeBase
ShapeContainer has a List of ShapeBaseRazorShapeComponent.razor takes a ShapeContainer Parameter
[Parameter]
public ShapeContainer ShapeContainer { get; set; }ShapeTest.cshtml.cs has: ShapeContainer MyShapeContainer { get; set; }
MyShapeContainer is instantiated in the ctorand:
ShapeTest.cshtml uses the RazorShapeComponent
<component type="typeof(RazorShapeComponent)" render-mode="ServerPrerendered" param-ShapeContainer='@Model.MyShapeContainer' />Behaviour
Then RazorShapeComponent.razor's OnInitialized() is called twice.The first time, the ShapeContainer parameter is initialized correctly
The second time, the List is initialized but contains instances of the base type
Regards,
Michael
Hello,
I encounter exactly the same problem as Michael. It was wrongly classified as a question, but this is a real issue.
Could you please reexamine it ?
This problem seams to be specific to ServerPrerendered mode, where components are initialized twice.
The first time, parameter is correctly deserialized, but second time the deserialization fails.
Workaround : serialize / deserialize complex types in a string parameter
Many thanks,
Jérôme

