dotnet / dotnet/runtime

System.Text.Json.Deserialize fails in published Blazor wasm

Open
#121,358 5 comments 0 reactions 0 assignees View on GitHub
arch-wasm area-System.Text.Json needs-further-triage os-browser question
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Description

### Description

`JsonSerializer.Deserialize` sets null to all properties of Microsoft.AspNetCore.Components.Authorization.ClaimData strurct in published wasm.

FYI, ClaimData is struct type that has parametered constructor that is decorated with [JsonConstructor] and all properties are readonly.

### Reproduction Steps

You can reproduce it only in ***published*** Blazor Webassembly.

```
using Microsoft.AspNetCore.Components.Authorization;

var options = new JsonSerializerOptions()
{
PropertyNameCaseInsensitive = true
};
var json = "{"type":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name","value":"myName"}";
var claimData = JsonSerializer.Deserialize(json, options);

var isClaimDataNull = claimData == null; // false
var isTypeNull = claimData.Type == null;
var isValueNull = claimData.Value == null;
```

### Expected behavior

isTypeNull: false;
isValueNull: false;

### Actual behavior

in non-published environments(debug and release);

isTypeNull: false
isValueNull: false

in published environments;

isTypeNull: true
isValueNull: true

### Regression?

I didn't try.

### Known Workarounds

Introduced a fully mutable class and used it to Deserialize:

```
class ClaimData
{
public string Type { get; set; } = default!;
public string Value { get; set; } = default!;
}
```

### Configuration

blazor : 9.0.3 with Microsoft Edge
Windows 10.
x64(AMD)
I don't think is relates to configuraions.

### Other information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.