-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JsonSerializer.Serialize throws when encountering nullable type in netstandard code paths #39208
Comments
JsonSerializer.Serialize not working well with nullable or workaround needed here. that is the problem |
If struct MyStruct changed to class MyStruct it will work also normally. |
FYI I ran the code on 3.1 (netcoreapp, not netstandard) and although it doesn't throw it does have an issue serializing nullable structs. The JSON from the test above:
It appears it is treating |
Minimal repro:
Exception:
Note that this does not reproduce in netcoreapp3.1 \ net5.0.
Describe the bug
When an object that is passed to
JSRuntime.InvokeVoidAsync
'sargs
contains a property that is a nullable value type (e.g.,System.Drawing.Point?
), and that property is set to a value, Blazor WASM throws an exception.To Reproduce
GitHub repo: https://github.com/chucker/blazorjsnullablevaluetype
Add a simple JS logging method to
index.html
'shead
:In
Index.razor
, add a struct, a class that takes the struct as property, and some code that instantiates the class and passes it to the JS method:This will work. Your browser will log:
Now, change the
Anchor
property to be nullable:This will throw an exception (see below) before the JS method ever gets called.
Exception
Further technical details
dotnet --info
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.15
OS Platform: Darwin
RID: osx.10.15-x64
Base Path: /usr/local/share/dotnet/sdk/3.1.301/
Host (useful for support):
Version: 3.1.5
Commit: 65cd789777
.NET Core SDKs installed:
3.1.301 [/usr/local/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.App 3.1.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.18 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.19 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
VS4Mac 8.7 Preview build 1802
(VS 16.7 Preview 3.1 is also affected)
Remarks
InvokeAsync<>
.The text was updated successfully, but these errors were encountered: