Skip to content

Calling Asynchronous .NET JS Interop Method Synchronously from JS Produces Misleading Error Message  #46811

Description

@daytonjallen

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Calling an asynchronous .NET JS Interop method synchronously produces an unhelpful/misleading error message.

These error messages (shown in steps to reproduce section) makes debugging the problem not very clear and seem mostly related to JSON Serialization - whereas that might not be the case.

Expected Behavior

Error message should indicate that this is an (unsupported workflow?) and warn against invoking async methods synchronously from JS or something that makes it easier to identify what the issue is.

Steps To Reproduce

Repo reproducing problem here: https://github.com/daytonjallen/JsonExceptionRepro

  1. Start new blazor wasm project
  2. Create async JSInvokable method from C#
  3. Call the above method from JS synchronously (DotNetObjectReference.invokeMethod)

Functions executes "successfully" and produces an exception in the console:
image

Also the error is different if we pass parameters:
image

Exceptions (if any)

Without Params:

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: System.NotSupportedException: SerializeTypeInstanceNotSupported, System.Action Path: $.MoveNextAction.
       ---> System.NotSupportedException: SerializeTypeInstanceNotSupported, System.Action
         at System.Text.Json.Serialization.Converters.UnsupportedTypeConverter`1[[System.Action, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Write(Utf8JsonWriter , Action , JsonSerializerOptions )
         at System.Text.Json.Serialization.JsonConverter`1[[System.Action, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWrite(Utf8JsonWriter , Action& , JsonSerializerOptions , WriteStack& )
         at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1[[System.Action, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetMemberAndWriteJson(Object , WriteStack& , Utf8JsonWriter )
         at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1[[System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[JsonExceptionRepro.Pages.Index.<LogHelloWorld>d__5, JsonExceptionRepro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnTryWrite(Utf8JsonWriter , AsyncStateMachineBox`1 , JsonSerializerOptions , WriteStack& )
         at System.Text.Json.Serialization.JsonConverter`1[[System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[JsonExceptionRepro.Pages.Index.<LogHelloWorld>d__5, JsonExceptionRepro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWrite(Utf8JsonWriter , AsyncStateMachineBox`1& , JsonSerializerOptions , WriteStack& )
         at System.Text.Json.Serialization.JsonConverter`1[[System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[JsonExceptionRepro.Pages.Index.<LogHelloWorld>d__5, JsonExceptionRepro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteCore(Utf8JsonWriter , AsyncStateMachineBox`1& , JsonSerializerOptions , WriteStack& )
         Exception_EndOfInnerExceptionStack
         at System.Text.Json.ThrowHelper.ThrowNotSupportedException(WriteStack& , NotSupportedException )
         at System.Text.Json.Serialization.JsonConverter`1[[System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[JsonExceptionRepro.Pages.Index.<LogHelloWorld>d__5, JsonExceptionRepro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteCore(Utf8JsonWriter , AsyncStateMachineBox`1& , JsonSerializerOptions , WriteStack& )
         at System.Text.Json.Serialization.JsonConverter`1[[System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[JsonExceptionRepro.Pages.Index.<LogHelloWorld>d__5, JsonExceptionRepro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteCoreAsObject(Utf8JsonWriter , Object , JsonSerializerOptions , WriteStack& )
         at System.Text.Json.JsonSerializer.WriteCore[Object](Utf8JsonWriter , Object& , JsonTypeInfo`1 )
         at System.Text.Json.JsonSerializer.WriteString[Object](Object& , JsonTypeInfo`1 )
         at System.Text.Json.JsonSerializer.Serialize[Object](Object , JsonSerializerOptions )
         at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.Invoke(JSRuntime , DotNetInvocationInfo& , String )
         at Microsoft.AspNetCore.Components.WebAssembly.Services.DefaultWebAssemblyJSRuntime.InvokeDotNet(String assemblyName, String methodIdentifier, String dotNetObjectId, String argsJson)
      Error: System.NotSupportedException: SerializeTypeInstanceNotSupported, System.Action Path: $.MoveNextAction.
       ---> System.NotSupportedException: SerializeTypeInstanceNotSupported, System.Action
         at System.Text.Json.Serialization.Converters.UnsupportedTypeConverter`1[[System.Action, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Write(Utf8JsonWriter , Action , JsonSerializerOptions )
         at System.Text.Json.Serialization.JsonConverter`1[[System.Action, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWrite(Utf8JsonWriter , Action& , JsonSerializerOptions , WriteStack& )
         at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1[[System.Action, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetMemberAndWriteJson(Object , WriteStack& , Utf8JsonWriter )
         at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1[[System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[JsonExceptionRepro.Pages.Index.<LogHelloWorld>d__5, JsonExceptionRepro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnTryWrite(Utf8JsonWriter , AsyncStateMachineBox`1 , JsonSerializerOptions , WriteStack& )
         at System.Text.Json.Serialization.JsonConverter`1[[System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[JsonExceptionRepro.Pages.Index.<LogHelloWorld>d__5, JsonExceptionRepro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWrite(Utf8JsonWriter , AsyncStateMachineBox`1& , JsonSerializerOptions , WriteStack& )
         at System.Text.Json.Serialization.JsonConverter`1[[System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[JsonExceptionRepro.Pages.Index.<LogHelloWorld>d__5, JsonExceptionRepro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteCore(Utf8JsonWriter , AsyncStateMachineBox`1& , JsonSerializerOptions , WriteStack& )
         Exception_EndOfInnerExceptionStack
         at System.Text.Json.ThrowHelper.ThrowNotSupportedException(WriteStack& , NotSupportedException )
         at System.Text.Json.Serialization.JsonConverter`1[[System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[JsonExceptionRepro.Pages.Index.<LogHelloWorld>d__5, JsonExceptionRepro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteCore(Utf8JsonWriter , AsyncStateMachineBox`1& , JsonSerializerOptions , WriteStack& )
         at System.Text.Json.Serialization.JsonConverter`1[[System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[JsonExceptionRepro.Pages.Index.<LogHelloWorld>d__5, JsonExceptionRepro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteCoreAsObject(Utf8JsonWriter , Object , JsonSerializerOptions , WriteStack& )
         at System.Text.Json.JsonSerializer.WriteCore[Object](Utf8JsonWriter , Object& , JsonTypeInfo`1 )
         at System.Text.Json.JsonSerializer.WriteString[Object](Object& , JsonTypeInfo`1 )
         at System.Text.Json.JsonSerializer.Serialize[Object](Object , JsonSerializerOptions )
         at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.Invoke(JSRuntime , DotNetInvocationInfo& , String )
         at Microsoft.AspNetCore.Components.WebAssembly.Services.DefaultWebAssemblyJSRuntime.InvokeDotNet(String assemblyName, String methodIdentifier, String dotNetObjectId, String argsJson)
          at qi (http://localhost/jsonexception/_framework/dotnet.7.0.3.4p3w76z2b4.js:5:80613)
          at Ji (http://localhost/jsonexception/_framework/dotnet.7.0.3.4p3w76z2b4.js:5:80497)
          at _Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_InvokeDotNet (https://dotnet.generated.invalid/_Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_InvokeDotNet:30:5)
          at Object.invokeDotNetFromJS (http://localhost/jsonexception/_framework/blazor.webassembly.js:1:45224)
          at g (http://localhost/jsonexception/_framework/blazor.webassembly.js:1:1621)
          at e.invokeMethod (http://localhost/jsonexception/_framework/blazor.webassembly.js:1:2670)
          at window.logHelloWorld (http://localhost/jsonexception:31:41)
          at http://localhost/jsonexception/_framework/blazor.webassembly.js:1:3337
          at new Promise (<anonymous>)
          at Object.beginInvokeJSFromDotNet (http://localhost/jsonexception/_framework/blazor.webassembly.js:1:3311)
Microsoft.JSInterop.JSException: System.NotSupportedException: SerializeTypeInstanceNotSupported, System.Action Path: $.MoveNextAction.
 ---> System.NotSupportedException: SerializeTypeInstanceNotSupported, System.Action
   at System.Text.Json.Serialization.Converters.UnsupportedTypeConverter`1[[System.Action, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Write(Utf8JsonWriter , Action , JsonSerializerOptions )
   at System.Text.Json.Serialization.JsonConverter`1[[System.Action, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWrite(Utf8JsonWriter , Action& , JsonSerializerOptions , WriteStack& )
   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1[[System.Action, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetMemberAndWriteJson(Object , WriteStack& , Utf8JsonWriter )
   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1[[System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[JsonExceptionRepro.Pages.Index.<LogHelloWorld>d__5, JsonExceptionRepro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnTryWrite(Utf8JsonWriter , AsyncStateMachineBox`1 , JsonSerializerOptions , WriteStack& )
   at System.Text.Json.Serialization.JsonConverter`1[[System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[JsonExceptionRepro.Pages.Index.<LogHelloWorld>d__5, JsonExceptionRepro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWrite(Utf8JsonWriter , AsyncStateMachineBox`1& , JsonSerializerOptions , WriteStack& )
   at System.Text.Json.Serialization.JsonConverter`1[[System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[JsonExceptionRepro.Pages.Index.<LogHelloWorld>d__5, JsonExceptionRepro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteCore(Utf8JsonWriter , AsyncStateMachineBox`1& , JsonSerializerOptions , WriteStack& )
   Exception_EndOfInnerExceptionStack
   at System.Text.Json.ThrowHelper.ThrowNotSupportedException(WriteStack& , NotSupportedException )
   at System.Text.Json.Serialization.JsonConverter`1[[System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[JsonExceptionRepro.Pages.Index.<LogHelloWorld>d__5, JsonExceptionRepro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteCore(Utf8JsonWriter , AsyncStateMachineBox`1& , JsonSerializerOptions , WriteStack& )
   at System.Text.Json.Serialization.JsonConverter`1[[System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[JsonExceptionRepro.Pages.Index.<LogHelloWorld>d__5, JsonExceptionRepro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteCoreAsObject(Utf8JsonWriter , Object , JsonSerializerOptions , WriteStack& )
   at System.Text.Json.JsonSerializer.WriteCore[Object](Utf8JsonWriter , Object& , JsonTypeInfo`1 )
   at System.Text.Json.JsonSerializer.WriteString[Object](Object& , JsonTypeInfo`1 )
   at System.Text.Json.JsonSerializer.Serialize[Object](Object , JsonSerializerOptions )
   at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.Invoke(JSRuntime , DotNetInvocationInfo& , String )
   at Microsoft.AspNetCore.Components.WebAssembly.Services.DefaultWebAssemblyJSRuntime.InvokeDotNet(String assemblyName, String methodIdentifier, String dotNetObjectId, String argsJson)
Error: System.NotSupportedException: SerializeTypeInstanceNotSupported, System.Action Path: $.MoveNextAction.
 ---> System.NotSupportedException: SerializeTypeInstanceNotSupported, System.Action
   at System.Text.Json.Serialization.Converters.UnsupportedTypeConverter`1[[System.Action, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Write(Utf8JsonWriter , Action , JsonSerializerOptions )
   at System.Text.Json.Serialization.JsonConverter`1[[System.Action, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWrite(Utf8JsonWriter , Action& , JsonSerializerOptions , WriteStack& )
   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1[[System.Action, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetMemberAndWriteJson(Object , WriteStack& , Utf8JsonWriter )
   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1[[System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[JsonExceptionRepro.Pages.Index.<LogHelloWorld>d__5, JsonExceptionRepro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnTryWrite(Utf8JsonWriter , AsyncStateMachineBox`1 , JsonSerializerOptions , WriteStack& )
   at System.Text.Json.Serialization.JsonConverter`1[[System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[JsonExceptionRepro.Pages.Index.<LogHelloWorld>d__5, JsonExceptionRepro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWrite(Utf8JsonWriter , AsyncStateMachineBox`1& , JsonSerializerOptions , WriteStack& )
   at System.Text.Json.Serialization.JsonConverter`1[[System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[JsonExceptionRepro.Pages.Index.<LogHelloWorld>d__5, JsonExceptionRepro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteCore(Utf8JsonWriter , AsyncStateMachineBox`1& , JsonSerializerOptions , WriteStack& )
   Exception_EndOfInnerExceptionStack
   at System.Text.Json.ThrowHelper.ThrowNotSupportedException(WriteStack& , NotSupportedException )
   at System.Text.Json.Serialization.JsonConverter`1[[System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[JsonExceptionRepro.Pages.Index.<LogHelloWorld>d__5, JsonExceptionRepro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteCore(Utf8JsonWriter , AsyncStateMachineBox`1& , JsonSerializerOptions , WriteStack& )
   at System.Text.Json.Serialization.JsonConverter`1[[System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[JsonExceptionRepro.Pages.Index.<LogHelloWorld>d__5, JsonExceptionRepro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteCoreAsObject(Utf8JsonWriter , Object , JsonSerializerOptions , WriteStack& )
   at System.Text.Json.JsonSerializer.WriteCore[Object](Utf8JsonWriter , Object& , JsonTypeInfo`1 )
   at System.Text.Json.JsonSerializer.WriteString[Object](Object& , JsonTypeInfo`1 )
   at System.Text.Json.JsonSerializer.Serialize[Object](Object , JsonSerializerOptions )
   at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.Invoke(JSRuntime , DotNetInvocationInfo& , String )
   at Microsoft.AspNetCore.Components.WebAssembly.Services.DefaultWebAssemblyJSRuntime.InvokeDotNet(String assemblyName, String methodIdentifier, String dotNetObjectId, String argsJson)
    at qi (http://localhost/jsonexception/_framework/dotnet.7.0.3.4p3w76z2b4.js:5:80613)
    at Ji (http://localhost/jsonexception/_framework/dotnet.7.0.3.4p3w76z2b4.js:5:80497)
    at _Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_InvokeDotNet (https://dotnet.generated.invalid/_Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_InvokeDotNet:30:5)
    at Object.invokeDotNetFromJS (http://localhost/jsonexception/_framework/blazor.webassembly.js:1:45224)
    at g (http://localhost/jsonexception/_framework/blazor.webassembly.js:1:1621)
    at e.invokeMethod (http://localhost/jsonexception/_framework/blazor.webassembly.js:1:2670)
    at window.logHelloWorld (http://localhost/jsonexception:31:41)
    at http://localhost/jsonexception/_framework/blazor.webassembly.js:1:3337
    at new Promise (<anonymous>)
    at Object.beginInvokeJSFromDotNet (http://localhost/jsonexception/_framework/blazor.webassembly.js:1:3311)
   at Microsoft.JSInterop.JSRuntime.<InvokeAsync>d__16`1[[Microsoft.JSInterop.Infrastructure.IJSVoidResult, Microsoft.JSInterop, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext()
   at Microsoft.JSInterop.JSRuntimeExtensions.InvokeVoidAsync(IJSRuntime , String , Object[] )
   at JsonExceptionRepro.Pages.Index.CallJsHello()
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task , ComponentState )

With Params:

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: System.NotSupportedException: ConstructorContainsNullParameterNames, System.Threading.Tasks.Task`1[System.Threading.Tasks.VoidTaskResult]
         at System.Text.Json.ThrowHelper.ThrowNotSupportedException_ConstructorContainsNullParameterNames(Type )
         at System.Text.Json.Serialization.Metadata.ReflectionJsonTypeInfo`1[[System.Threading.Tasks.Task`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetParameterInfoValues()
         at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure()
         at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureLocked|143_0()
         at System.Text.Json.Serialization.Metadata.JsonTypeInfo.EnsureConfigured()
         at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type , Boolean , Boolean )
         at System.Text.Json.JsonSerializer.ResolvePolymorphicTypeInfo[Object](Object& , JsonTypeInfo , Boolean& )
         at System.Text.Json.JsonSerializer.WriteCore[Object](Utf8JsonWriter , Object& , JsonTypeInfo`1 )
         at System.Text.Json.JsonSerializer.WriteString[Object](Object& , JsonTypeInfo`1 )
         at System.Text.Json.JsonSerializer.Serialize[Object](Object , JsonSerializerOptions )
         at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.Invoke(JSRuntime , DotNetInvocationInfo& , String )
         at Microsoft.AspNetCore.Components.WebAssembly.Services.DefaultWebAssemblyJSRuntime.InvokeDotNet(String assemblyName, String methodIdentifier, String dotNetObjectId, String argsJson)
      Error: System.NotSupportedException: ConstructorContainsNullParameterNames, System.Threading.Tasks.Task`1[System.Threading.Tasks.VoidTaskResult]
         at System.Text.Json.ThrowHelper.ThrowNotSupportedException_ConstructorContainsNullParameterNames(Type )
         at System.Text.Json.Serialization.Metadata.ReflectionJsonTypeInfo`1[[System.Threading.Tasks.Task`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetParameterInfoValues()
         at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure()
         at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureLocked|143_0()
         at System.Text.Json.Serialization.Metadata.JsonTypeInfo.EnsureConfigured()
         at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type , Boolean , Boolean )
         at System.Text.Json.JsonSerializer.ResolvePolymorphicTypeInfo[Object](Object& , JsonTypeInfo , Boolean& )
         at System.Text.Json.JsonSerializer.WriteCore[Object](Utf8JsonWriter , Object& , JsonTypeInfo`1 )
         at System.Text.Json.JsonSerializer.WriteString[Object](Object& , JsonTypeInfo`1 )
         at System.Text.Json.JsonSerializer.Serialize[Object](Object , JsonSerializerOptions )
         at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.Invoke(JSRuntime , DotNetInvocationInfo& , String )
         at Microsoft.AspNetCore.Components.WebAssembly.Services.DefaultWebAssemblyJSRuntime.InvokeDotNet(String assemblyName, String methodIdentifier, String dotNetObjectId, String argsJson)
          at qi (http://localhost/jsonexception6/_framework/dotnet.7.0.3.4p3w76z2b4.js:5:80613)
          at Ji (http://localhost/jsonexception6/_framework/dotnet.7.0.3.4p3w76z2b4.js:5:80497)
          at _Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_InvokeDotNet (https://dotnet.generated.invalid/_Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_InvokeDotNet:30:5)
          at Object.invokeDotNetFromJS (http://localhost/jsonexception6/_framework/blazor.webassembly.js:1:45224)
          at g (http://localhost/jsonexception6/_framework/blazor.webassembly.js:1:1621)
          at A.invokeMethod (http://localhost/jsonexception6/_framework/blazor.webassembly.js:1:3812)
          at window.logHelloWorld (http://localhost/jsonexception6:34:16)
          at http://localhost/jsonexception6/_framework/blazor.webassembly.js:1:3337
          at new Promise (<anonymous>)
          at Object.beginInvokeJSFromDotNet (http://localhost/jsonexception6/_framework/blazor.webassembly.js:1:3311)
Microsoft.JSInterop.JSException: System.NotSupportedException: ConstructorContainsNullParameterNames, System.Threading.Tasks.Task`1[System.Threading.Tasks.VoidTaskResult]
   at System.Text.Json.ThrowHelper.ThrowNotSupportedException_ConstructorContainsNullParameterNames(Type )
   at System.Text.Json.Serialization.Metadata.ReflectionJsonTypeInfo`1[[System.Threading.Tasks.Task`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetParameterInfoValues()
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure()
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureLocked|143_0()
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.EnsureConfigured()
   at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type , Boolean , Boolean )
   at System.Text.Json.JsonSerializer.ResolvePolymorphicTypeInfo[Object](Object& , JsonTypeInfo , Boolean& )
   at System.Text.Json.JsonSerializer.WriteCore[Object](Utf8JsonWriter , Object& , JsonTypeInfo`1 )
   at System.Text.Json.JsonSerializer.WriteString[Object](Object& , JsonTypeInfo`1 )
   at System.Text.Json.JsonSerializer.Serialize[Object](Object , JsonSerializerOptions )
   at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.Invoke(JSRuntime , DotNetInvocationInfo& , String )
   at Microsoft.AspNetCore.Components.WebAssembly.Services.DefaultWebAssemblyJSRuntime.InvokeDotNet(String assemblyName, String methodIdentifier, String dotNetObjectId, String argsJson)
Error: System.NotSupportedException: ConstructorContainsNullParameterNames, System.Threading.Tasks.Task`1[System.Threading.Tasks.VoidTaskResult]
   at System.Text.Json.ThrowHelper.ThrowNotSupportedException_ConstructorContainsNullParameterNames(Type )
   at System.Text.Json.Serialization.Metadata.ReflectionJsonTypeInfo`1[[System.Threading.Tasks.Task`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetParameterInfoValues()
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure()
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureLocked|143_0()
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.EnsureConfigured()
   at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type , Boolean , Boolean )
   at System.Text.Json.JsonSerializer.ResolvePolymorphicTypeInfo[Object](Object& , JsonTypeInfo , Boolean& )
   at System.Text.Json.JsonSerializer.WriteCore[Object](Utf8JsonWriter , Object& , JsonTypeInfo`1 )
   at System.Text.Json.JsonSerializer.WriteString[Object](Object& , JsonTypeInfo`1 )
   at System.Text.Json.JsonSerializer.Serialize[Object](Object , JsonSerializerOptions )
   at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.Invoke(JSRuntime , DotNetInvocationInfo& , String )
   at Microsoft.AspNetCore.Components.WebAssembly.Services.DefaultWebAssemblyJSRuntime.InvokeDotNet(String assemblyName, String methodIdentifier, String dotNetObjectId, String argsJson)
    at qi (http://localhost/jsonexception6/_framework/dotnet.7.0.3.4p3w76z2b4.js:5:80613)
    at Ji (http://localhost/jsonexception6/_framework/dotnet.7.0.3.4p3w76z2b4.js:5:80497)
    at _Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_InvokeDotNet (https://dotnet.generated.invalid/_Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_InvokeDotNet:30:5)
    at Object.invokeDotNetFromJS (http://localhost/jsonexception6/_framework/blazor.webassembly.js:1:45224)
    at g (http://localhost/jsonexception6/_framework/blazor.webassembly.js:1:1621)
    at A.invokeMethod (http://localhost/jsonexception6/_framework/blazor.webassembly.js:1:3812)
    at window.logHelloWorld (http://localhost/jsonexception6:34:16)
    at http://localhost/jsonexception6/_framework/blazor.webassembly.js:1:3337
    at new Promise (<anonymous>)
    at Object.beginInvokeJSFromDotNet (http://localhost/jsonexception6/_framework/blazor.webassembly.js:1:3311)
   at Microsoft.JSInterop.JSRuntime.<InvokeAsync>d__16`1[[Microsoft.JSInterop.Infrastructure.IJSVoidResult, Microsoft.JSInterop, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext()
   at Microsoft.JSInterop.JSRuntimeExtensions.InvokeVoidAsync(IJSRuntime , String , Object[] )
   at Test.Pages.Index.CallJsHello()
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task , ComponentState )

.NET Version

7.0.200

Anything else?

Visual Studio Version: 17.5.0

image

Activity

  1. added
    area-blazor
    feature-blazor-wasm
    feature-blazor-jsinterop
    bug
    help wanted
    good first issue
    on Feb 22, 2023
  2. added this to the Backlog milestone on Feb 23, 2023
  3. shiladitya-mukerji-22 commented on Mar 16, 2023

    @shiladitya-mukerji-22
    Contributor

    Hey @mkArtakMSFT, I would like to work on this issue.

  4. added and removed
    help wanted
    on Oct 28, 2023
  5. mkArtakMSFT commented on Nov 9, 2023

    @mkArtakMSFT
    Contributor

    @shiladitya-mukerji-22 I just found your message accidentally.
    If you want, you can wait for us to drop a summary comment, which will hopefully give you hints regarding how to proceed and what approach to take. If you are confident that you can handle it without it, feel free to send us a PR and we'll get somebody review it.

  6. 4 remaining items

  7. added
    Priority:2
    on Jan 18, 2024
  8. DanielCoder834 commented on Sep 30, 2025

    @DanielCoder834

    Hey, if this issue is still available, could I work on it?

  9. DanielCoder834 commented on Oct 30, 2025

    @DanielCoder834

    Hi, I have been trying to figure out how to fix this issue, but I am a bit stuck. In a previous comment, there was a mention of adding a summary comment. Is that still being worked on and is there any recommendation on where to start editing and testing?

    I have tried to looking into the src/JSInterop/Microsoft.JSInterop/src/JSRuntime.cs, the src/Components/WebAssembly/WebAssembly/src/Rendering/WebAssemblyRenderer.cs, and the src/Components/WebAssembly/WebAssembly/src/Services/DefaultWebAssemblyJSRuntime.cs. Are those the files I should be looking through?

    Also, is there a way to test Razor applications in the codebase? I am not seeing any Razor files in the test folder.

    Thank you for any help on this.

  10. added
    help wanted
    and removed on Jan 7, 2026
  11. added 2 commits that reference this issue on Mar 20, 2026
    bfacf3d
    f28aff8
  12. raphaelfribeiro commented on May 19, 2026

    @raphaelfribeiro

    Hi @mkArtakMSFT — is this issue still open for a community PR? I noticed the copilot-candidate label and want to confirm before investing time.

    @DanielCoder834 — are you still working on this? Happy to step back if so, otherwise I'd like to pick it up.

    My current read: the misleading message surfaces because DotNetDispatcher.Invoke (sync path) tries to JsonSerializer.Serialize the Task returned by an [JSInvokable] async method, which fails when serializing the async state machine's MoveNextAction. The user-facing fix would be to detect Task/ValueTask return types at the synchronous invocation entry point and throw an InvalidOperationException pointing them to invokeMethodAsync — before reaching the serializer. Does that direction match what you'd want? I'd add unit coverage in Microsoft.JSInterop.Tests plus an E2E in the Blazor WASM test app.

    Thanks!

  13. shantanu2002git commented on Oct 5, 2026

    @shantanu2002git

    I've submitted #69659 to address this issue.
    Wating for review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pillar: Dev ExperiencePriority:2area-blazorbugcopilot-candidatefeature-blazor-jsinteropfeature-blazor-wasmgood first issuehelp wanted

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions