You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unhandled Exception: System.ArgumentException: GenericArguments[0], 'System.Nullable`1[ConsoleApp12.MyStruct]', on 'System.Func`2[System.Object,TProperty] CreateStructPropertyGetter[TClass,TProperty](GetPropertyByRef`2)' violates the constraint of type 'TClass'. ---> System.Security.VerificationException: Method System.Text.Json.ReflectionMemberAccessor.CreateStructPropertyGetter: type argument 'System.Nullable`1[ConsoleApp12.MyStruct]' violates the constraint of type parameter 'TClass'.
at System.RuntimeMethodHandle.GetStubIfNeeded(RuntimeMethodHandleInternal method, RuntimeType declaringType, RuntimeType[] methodInstantiation)
at System.Reflection.RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation)
--- End of inner exception stack trace ---
at System.RuntimeType.ValidateGenericArguments(MemberInfo definition, RuntimeType[] genericArguments, Exception e)
at System.Reflection.RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation)
at System.Text.Json.ReflectionMemberAccessor.CreatePropertyGetter[TClass,TProperty](PropertyInfo propertyInfo)
at System.Text.Json.JsonPropertyInfoCommon`4.Initialize(Type parentClassType, Type declaredPropertyType, Type runtimePropertyType, Type implementedPropertyType, PropertyInfo propertyInfo, Type elementType, JsonConverter converter, JsonSerializerOptions options)
Note that this does not reproduce in netcoreapp3.1 \ net5.0.
Describe the bug
When an object that is passed to JSRuntime.InvokeVoidAsync's args 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.
pranavkm
changed the title
Blazor WASM: cannot pass nullable value type property to JS interop
JsonSerializer.Serialize throws when encountering nullable type in netstandard code paths
Jul 13, 2020
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: