Skip to content

ServerPrerendered Blazor component in Razor pages doesn't serialize parameter correctly #22812

@jerome-raffalli

Description

@jerome-raffalli

Visual Studio 2019 16.6.1
.Net Core 3.1.4

Using 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.cs

Where:
ShapeTriangle extends ShapeBase
ShapeContainer has a List of ShapeBase

RazorShapeComponent.razor takes a ShapeContainer Parameter
[Parameter]
public ShapeContainer ShapeContainer { get; set; }

ShapeTest.cshtml.cs has: ShapeContainer MyShapeContainer { get; set; }
MyShapeContainer is instantiated in the ctor

and:
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
image

The second time, the List is initialized but contains instances of the base type
image

BugLog.zip

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions