Skip to content

[.NET 10 Preview 5] Blazor Web WebAssembly Mode crashes related with JsonSerialization #62350

Open
@Kumima

Description

@Kumima

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I enable the System.Text.Json.Serialization.RespectRequiredConstructorParametersDefault as true for my projects. See: https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/required-properties#feature-switch

It works fine before, but after updating to Preview5, I got:

AggregateException_ctor_DefaultMessage (An exception occurred executing JS interop: JsonRequiredPropertiesMissing, Microsoft.AspNetCore.Components.ResourceAsset, 'properties'. See InnerException for more details.)
    at un (marshal-to-js.ts:421:18)
    at rn.resolve_or_reject (marshal-to-js.ts:315:28)
    at marshal-to-js.ts:364:16
    at marshal-to-js.ts:341:48
    at gr (invoke-js.ts:528:9)
    at Mc (marshal-to-js.ts:341:5)
    at dotnet.native.ulywfn9r8g.wasm:0x1f60f
    at dotnet.native.ulywfn9r8g.wasm:0x1ca55
    at dotnet.native.ulywfn9r8g.wasm:0xeb73
    at dotnet.native.ulywfn9r8g.wasm:0x1f0f3

To disable RespectRequiredConstructorParametersDefault will fix, this seems a break change, and I want to keep my RespectRequiredConstructorParametersDefault as true.

My guess is Preview5 deserializes Microsoft.AspNetCore.Components.ResourceAsset without all required properties.

Describe the solution you'd like

With System.Text.Json.Serialization.RespectRequiredConstructorParametersDefault as true won't break my Blazor Web application. An approach is to make sure all required properties presented in the json string. Or:

public sealed class ResourceAsset(string url, IReadOnlyList<ResourceAssetProperty>? properties);
// Make the second param optional
public sealed class ResourceAsset(string url, IReadOnlyList<ResourceAssetProperty>? properties = null);

Additional context

My .NET SDK Version: 10.0.100-preview.5.25277.114
I'm using preview5 nuget packages for all my Blazor related packages.

Metadata

Metadata

Assignees

Labels

area-blazorIncludes: Blazor, Razor Components

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions