Skip to content

System.InvalidOperationException when using touch events (TouchEventArgs) in Blazor with ASP.NET Core in .NET 6 Preview 3 #32357

@lambrech

Description

@lambrech

Describe the bug

When ASP.NET Core in .NET 6 Preview 3 tries to deserialize the browsers "TouchEventArgs" a System.InvalidOperationException is thrown.

To Reproduce

I created a basic blazor webassembly app with .NET 6 preview 3 and hooked up an 'ontouchmove' event handler in the MainLayout.razor to log the ClientX Position of the touch event. This works perfectly when starting from debugger or 'dotnet watch' and simulating touch event by using e.g. Chrome dev tools.

When I publish the app to github pages or use another static file server I get an InvalidOperationException whenever blazor tries to parse the TouchEventArgs (this happens whenever I "touch around" on the page).

I tested and reproduced this bug with Chrome, Edge and Firefox.
Note: In Firefox sometimes the console does not output the error right away (nor the console log that should be visible). Refreshing Firefox wiht Ctrl + F5 make the exception appear (after "touching around" again).

The published page is available here: https://lambrech.github.io/BasicBlazorWebAssemblyPwaGithubPagesApp/
Code can be found here: https://github.com/lambrech/BasicBlazorWebAssemblyPwaGithubPagesApp

FYI: I tested this with .NET 5 and it works even after publishing.

Exceptions (if any)

Uncaught (in promise) Error: System.InvalidOperationException: There was an error parsing the event arguments. EventId: '1'.
---> System.NotSupportedException: DeserializeNoConstructor, JsonConstructorAttribute, Microsoft.AspNetCore.Components.Web.TouchPoint Path: $.touches[0] | LineNumber: 0 | BytePositionInLine: 24.
---> System.NotSupportedException: DeserializeNoConstructor, JsonConstructorAttribute, Microsoft.AspNetCore.Components.Web.TouchPoint
Exception_EndOfInnerExceptionStack
at System.Text.Json.ThrowHelper.ThrowNotSupportedException(ReadStack& state, Utf8JsonReader& reader, NotSupportedException ex)
at System.Text.Json.ThrowHelper.ThrowNotSupportedException_DeserializeNoConstructor(Type type, Utf8JsonReader& reader, ReadStack& state)
at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1[[Microsoft.AspNetCore.Components.Web.TouchPoint, Microsoft.AspNetCore.Components.Web, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, TouchPoint& value) at System.Text.Json.Serialization.JsonConverter1[[Microsoft.AspNetCore.Components.Web.TouchPoint, Microsoft.AspNetCore.Components.Web, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, TouchPoint& value)
at System.Text.Json.Serialization.Converters.IEnumerableDefaultConverter2[[Microsoft.AspNetCore.Components.Web.TouchPoint[], Microsoft.AspNetCore.Components.Web, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[Microsoft.AspNetCore.Components.Web.TouchPoint, Microsoft.AspNetCore.Components.Web, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, TouchPoint[]& value) at System.Text.Json.Serialization.JsonConverter1[[Microsoft.AspNetCore.Components.Web.TouchPoint[], Microsoft.AspNetCore.Components.Web, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, TouchPoint[]& value)
at System.Text.Json.JsonPropertyInfo1[[Microsoft.AspNetCore.Components.Web.TouchPoint[], Microsoft.AspNetCore.Components.Web, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader) at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1[[Microsoft.AspNetCore.Components.Web.TouchEventArgs, Microsoft.AspNetCore.Components.Web, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, TouchEventArgs& value)
at System.Text.Json.Serialization.JsonConverter1[[Microsoft.AspNetCore.Components.Web.TouchEventArgs, Microsoft.AspNetCore.Components.Web, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, TouchEventArgs& value) at System.Text.Json.Serialization.JsonConverter1[[Microsoft.AspNetCore.Components.Web.TouchEventArgs, Microsoft.AspNetCore.Components.Web, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.JsonSerializer.ReadCore[TouchEventArgs](JsonConverter jsonConverter, Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.JsonSerializer.ReadCore[TouchEventArgs](Utf8JsonReader& reader, Type returnType, JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.Deserialize[TouchEventArgs](ReadOnlySpan`1 json, Type returnType, JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.Deserialize[TouchEventArgs](String json, JsonSerializerOptions options)
at Microsoft.AspNetCore.Components.Web.WebEventData.Deserialize[TouchEventArgs](String json)
at Microsoft.AspNetCore.Components.Web.WebEventData.TryDeserializeStandardWebEventArgs(String eventName, String eventArgsJson, EventArgs& eventArgs)
at Microsoft.AspNetCore.Components.Web.WebEventData.ParseEventArgsJson(Renderer renderer, UInt64 eventHandlerId, String eventName, String eventArgsJson)
Exception_EndOfInnerExceptionStack
at Microsoft.AspNetCore.Components.Web.WebEventData.ParseEventArgsJson(Renderer renderer, UInt64 eventHandlerId, String eventName, String eventArgsJson)
at Microsoft.AspNetCore.Components.Web.WebEventData.Parse(Renderer renderer, WebEventDescriptor eventDescriptor, String eventArgsJson)
at Microsoft.AspNetCore.Components.WebAssembly.Infrastructure.JSInteropMethods.DispatchEvent(WebEventDescriptor eventDescriptor, String eventArgsJson)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
--- End of stack trace from previous location ---
at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.InvokeSynchronously(JSRuntime jsRuntime, DotNetInvocationInfo& callInfo, IDotNetObjectReference objectReference, String argsJson)
at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.BeginInvokeDotNet(JSRuntime jsRuntime, DotNetInvocationInfo invocationInfo, String argsJson)

Further technical details

  • ASP.NET Core version: .NET 6 Preview 3

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions