Skip to content
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

DateOnly passing to JSRuntime no longer supported in Blazor 6.0.0-rc.1 #36631

Closed
naefp opened this issue Sep 16, 2021 · 4 comments
Closed

DateOnly passing to JSRuntime no longer supported in Blazor 6.0.0-rc.1 #36631

naefp opened this issue Sep 16, 2021 · 4 comments
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-jsinterop This issue is related to JSInterop in Blazor ✔️ Resolution: Duplicate Resolved as a duplicate of another issue investigate Status: Resolved

Comments

@naefp
Copy link

naefp commented Sep 16, 2021

Describe the bug

System.Text.Json.Serialization.JsonConverter throws an exception when a DateOnly value is passed to JSRuntime in Blazor. The error occurs with 6.0.0-rc.1, but this worked in 6.0.0-preview.7.

Could be a bug or could be expected behavior, I'm not sure.

To Reproduce

Pass a DateOnly value to the JSRuntime in Blazor:

await JsRuntime.InvokeVoidAsync("your_js_function", YourDateOnlyValue);

Exceptions (if any)

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Serialization and deserialization of 'System.DateOnly' instances are not supported and should be avoided since they can lead to security issues. The unsupported member type is located on type 'System.Object'. Path: $.
System.NotSupportedException: Serialization and deserialization of 'System.DateOnly' instances are not supported and should be avoided since they can lead to security issues. The unsupported member type is located on type 'System.Object'. Path: $.
 ---> System.NotSupportedException: Serialization and deserialization of 'System.DateOnly' instances are not supported and should be avoided since they can lead to security issues.
   at System.Text.Json.Serialization.Converters.DisallowedTypeConverter`1[[System.DateOnly, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Write(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options)
   at System.Text.Json.Serialization.JsonConverter`1[[System.DateOnly, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWrite(Utf8JsonWriter writer, DateOnly& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[System.DateOnly, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWriteAsObject(Utf8JsonWriter writer, Object value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWrite(Utf8JsonWriter writer, Object& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Converters.ArrayConverter`2[[System.Object[], System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnWriteResume(Utf8JsonWriter writer, Object[] array, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonCollectionConverter`2[[System.Object[], System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnTryWrite(Utf8JsonWriter writer, Object[] value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Object[], System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWrite(Utf8JsonWriter writer, Object[]& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Object[], System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteCore(Utf8JsonWriter writer, Object[]& value, JsonSerializerOptions options, WriteStack& state)
   --- End of inner exception stack trace ---
   at System.Text.Json.ThrowHelper.ThrowNotSupportedException(WriteStack& state, NotSupportedException ex)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Object[], System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteCore(Utf8JsonWriter writer, Object[]& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.JsonSerializer.WriteUsingSerializer[Object[]](Utf8JsonWriter writer, Object[]& value, JsonTypeInfo jsonTypeInfo)
   at System.Text.Json.JsonSerializer.WriteStringUsingSerializer[Object[]](Object[]& value, JsonTypeInfo jsonTypeInfo)
   at System.Text.Json.JsonSerializer.Serialize[Object[]](Object[] value, JsonSerializerOptions options)
   at Microsoft.JSInterop.JSRuntime.InvokeAsync[Object](Int64 targetInstanceId, String identifier, CancellationToken cancellationToken, Object[] args)
   at Microsoft.JSInterop.JSRuntime.<InvokeAsync>d__16`1[[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at Microsoft.JSInterop.JSRuntimeExtensions.InvokeVoidAsync(IJSRuntime jsRuntime, String identifier, Object[] args)

Further technical details

  • ASP.NET Core version: 6.0.100-rc.1.21458.32
@TanayParikh TanayParikh added the area-blazor Includes: Blazor, Razor Components label Sep 16, 2021
@TanayParikh
Copy link
Contributor

@simonziegler
Copy link

simonziegler commented Sep 19, 2021

+1 this is an urgent requirement for me.

@danroth27 - I thought it might be worth tagging you for this. Lack of support for DateOnly and TimeOnly in STJ means that all Blazor JS Interop that relies on either type needs to be wrapped with a workaround.

@javiercn javiercn added the feature-blazor-jsinterop This issue is related to JSInterop in Blazor label Sep 20, 2021
@javiercn
Copy link
Member

@simonziegler you can place a converter on the property and that will take effect.

@mkArtakMSFT mkArtakMSFT added this to the 6.0.0 milestone Sep 20, 2021
@mkArtakMSFT mkArtakMSFT modified the milestones: 6.0.0, .NET 7 Planning Oct 4, 2021
@mkArtakMSFT
Copy link
Member

We're closing this issue as there is no work we (the Blazor Team) have to do here to explicitly support this. There is an existing runtime issue tracking adding support for this for JsonSerializer.

@mkArtakMSFT mkArtakMSFT added the ✔️ Resolution: Duplicate Resolved as a duplicate of another issue label Oct 4, 2021
@ghost ghost added the Status: Resolved label Oct 4, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Nov 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-jsinterop This issue is related to JSInterop in Blazor ✔️ Resolution: Duplicate Resolved as a duplicate of another issue investigate Status: Resolved
Projects
None yet
Development

No branches or pull requests

5 participants