Skip to content

There is an error "An exception occurred executing JS interop: DeserializeUnableToConvertValue" in browser console when running the published WebWorker with Blazor WASM app #66346

Closed

Description

@jinzhao1127

REGRESSION INFO: Works well on 11.0 Preview 3

INSTALL STEPS

  1. Clean Win11 x64 23h2 ENU
  2. Install the .NET 11.0 preview 4
  3. Apply feed

Platform

  • Windows
  • macOS
  • Linux

Repro Steps

  1. Open a normal Command Prompt
  2. Create a Blazor WebAssembly Standalone App with a WebWorker library
dotnet new blazorwasm -n MyApp
dotnet new blazorwebworker -n MyWebWorker
  1. Add a project reference from the Blazor app to the WebWorker library:
cd MyApp
dotnet add reference ../MyWebWorker/MyWebWorker.csproj
  1. Open .csproj of Blazor WebAssembly app and add the following inside the existing :
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>

  2. Create a Myworker.cs file in the Blazor WebAssembly app, add following code snip.

using System.Runtime.InteropServices.JavaScript;
using System.Runtime.Versioning;
using System.Text.Json;

namespace MyApp
{
    [SupportedOSPlatform("browser")]
    public static partial class MyWorker
    {
        [JSExport]
        public static string Greet(string name) => $"Hello, {name}!";
        [JSExport]
        public static string GetUsers()
        {
            var users = new List<User> { new("Alice", 30), new("Bob", 25) };
            return JsonSerializer.Serialize(users);  // Serialize before returning
        }
    }
    public record User(string Name, int Age);
}
  1. In the Home.razor file, add the following code.
@inject IJSRuntime JSRuntime
@using MyWebWorker

@code {
    protected override async Task OnInitializedAsync()
    {
        await using var worker = await WebWorkerClient.CreateAsync(JSRuntime);
        
        Console.WriteLine("Worker created?");
        
        var greeting = await worker.InvokeAsync<string>("MyApp.MyWorker.Greet", ["World"]);
        var users = await worker.InvokeAsync<List<User>>("MyApp.MyWorker.GetUsers", []);
    }
}
  1. Install the dotnet-serve tool
    dotnet tool install --global dotnet-serve

  2. Publish the application to folder:
    dotnet publish -c Release

  3. Go to the publish output directory and run dotnet-serve -S:

cd bin\Release\net11.0\publish\wwwroot
dotnet-serve -S
  1. Open a browser and navigate to the URL

Note:

  1. This issue does not repro when dotnet run
  2. I notices that the webworker template change to blazorwebworker

Actual Result
An unhandled error has occurred.

Image

Error Log

blazor.webassembly.tmoplnooj7.js:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: An exception occurred executing JS interop: DeserializeUnableToConvertValue, System.Collections.Generic.List`1[MyApp.User] Path: $ | LineNumber: 0 | BytePositionInLine: 65.. See InnerException for more details.
Microsoft.JSInterop.JSException: An exception occurred executing JS interop: DeserializeUnableToConvertValue, System.Collections.Generic.List`1[MyApp.User] Path: $ | LineNumber: 0 | BytePositionInLine: 65.. See InnerException for more details.
 ---> System.Text.Json.JsonException: DeserializeUnableToConvertValue, System.Collections.Generic.List`1[MyApp.User] Path: $ | LineNumber: 0 | BytePositionInLine: 65.
   at System.Text.Json.ThrowHelper.ThrowJsonException_DeserializeUnableToConvertValue(Type)
   at System.Text.Json.Serialization.JsonCollectionConverter`2[[System.Collections.Generic.List`1[[MyApp.User, MyApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=11.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[MyApp.User, MyApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].OnTryRead(Utf8JsonReader&, Type, JsonSerializerOptions, ReadStack& , List`1& )
   at System.Text.Json.Serialization.JsonConverter`1[[System.Collections.Generic.List`1[[MyApp.User, MyApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=11.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryRead(Utf8JsonReader&, Type, JsonSerializerOptions, ReadStack& , List`1& , Boolean& )
   at System.Text.Json.Serialization.JsonConverter`1[[System.Collections.Generic.List`1[[MyApp.User, MyApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=11.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ReadCore(Utf8JsonReader&, List`1& , JsonSerializerOptions, ReadStack&)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1[[System.Collections.Generic.List`1[[MyApp.User, MyApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=11.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Deserialize(Utf8JsonReader&, ReadStack&)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1[[System.Collections.Generic.List`1[[MyApp.User, MyApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=11.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].DeserializeAsObject(Utf8JsonReader&, ReadStack&)
   at System.Text.Json.JsonSerializer.ReadAsObject(Utf8JsonReader&, JsonTypeInfo)
   at System.Text.Json.JsonSerializer.Deserialize(Utf8JsonReader&, Type , JsonSerializerOptions )
   at Microsoft.JSInterop.JSRuntime.EndInvokeJS(Int64, Boolean, Utf8JsonReader&)
   Exception_EndOfInnerExceptionStack
   at MyWebWorker.WebWorkerClient.<InvokeAsync>d__5`1[[System.Collections.Generic.List`1[[MyApp.User, MyApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=11.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at MyApp.Pages.Home.OnInitializedAsync()
   at MyApp.Pages.Home.OnInitializedAsync()
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task, ComponentState)

Activity

  1. added
    area-blazor
    on Apr 17, 2026
  2. jinzhao1127 commented on Apr 17, 2026

    @jinzhao1127
    Author

    @ilonatommy, could you look at this bug?

  3. added
    bug
    on Apr 17, 2026
  4. github-actions commented on Apr 17, 2026

    @github-actions
    Contributor

    Triage Summary

    Area: area-blazor (already labeled — Blazor WebAssembly JSInterop deserialization failure with WebWorker)
    Type: bug — A clear regression with repro steps; worker.InvokeAsync<List<User>> throws DeserializeUnableToConvertValue when running a published WASM app with a WebWorker, but works fine with dotnet run.

    Regression Info

    • Previously working version: .NET 11.0 Preview 3
    • Broken since: .NET 11.0 Preview 4
    • The worker.InvokeAsync<List<T>> call successfully deserializes the JSON-serialized return value in Preview 3, but fails with a JsonException (DeserializeUnableToConvertValue) in Preview 4. The issue only reproduces when the app is published (not dotnet run), suggesting the regression may be related to trimming/AOT/linker metadata changes between previews.

    Potential Duplicates

    • None found

    Notes

    • The stack trace points to Microsoft.JSInterop.JSRuntime.EndInvokeJS failing to deserialize the return value — the JSON content is a valid serialized List<User> (string returned from the worker), but the JSInterop deserialization on the main thread fails. This is likely a trimming or type-metadata issue introduced in Preview 4 that removes the JSON converter for List<T> in the published output.
    • Worth cross-checking against runtime/linker trimming changes between Preview 3 → Preview 4.
    • Does not reproduce with dotnet run (no publishing/trimming involved), which strongly points to a publish-time trim annotation or AOT metadata issue.

    Generated by Issue Triage Agent for dotnet/aspnetcore for issue #66346 · ● 173.4K · ◷

  5. self-assigned this
    on Apr 17, 2026
  6. ilonatommy commented on Apr 17, 2026

    @ilonatommy
    Member

    @jinzhao1127, can you use this instruction: https://github.com/dotnet/AspNetCore-ManualTests/pull/3739 and let me know if it works?

  7. jinzhao1127 commented on Apr 20, 2026

    @jinzhao1127
    Author

    @jinzhao1127, can you use this instruction: dotnet/AspNetCore-ManualTests#3739 and let me know if it works?

    @ilonatommy , Yes this issue also reproduces on the instruction https://github.com/dotnet/AspNetCore-ManualTests/pull/3739,

    Image
  8. added this to the .NET 11 Planning milestone on Apr 20, 2026
  9. KristofferStrube commented on Apr 20, 2026

    @KristofferStrube
    Contributor

    I can replicate this in ASP.NET Core 11 Preview 4, using dotnet run as well.

    I think the primary reason for this behavior is the change made in commit ab49dc8 as part of #66070, which means we can no longer return complex objects without handling serialization and deserialization ourselves.

    I can't view the pull request you linked, so I don't know if you suggested the same change. If I change the Razor page in the reproduction steps to the following, it works for me in Preview 4.

    @inject IJSRuntime JSRuntime
    @using MyWebWorker
    @using System.Text.Json
    
    @code {
        protected override async Task OnInitializedAsync()
        {
            await using var worker = await WebWorkerClient.CreateAsync(JSRuntime);
            
            Console.WriteLine("Worker created?");
            
            var greeting = await worker.InvokeAsync<string>("MyApp.MyWorker.Greet", ["World"]);
            var usersAsString = await worker.InvokeAsync<string>("MyApp.MyWorker.GetUsers", []);
            var users = JsonSerializer.Deserialize<List<User>>(usersAsString);
        }
    }
  10. ilonatommy commented on Apr 22, 2026

    @ilonatommy
    Member

    I can't view the pull request you linked, so I don't know if you suggested the same change. If I change the Razor page in the reproduction steps to the following, it works for me in Preview 4.

    Exactly, deserialization is now required. @jinzhao1127 are you sure you changed

     var person = await worker.InvokeAsync<Person>("BlazorWasmApp.Workers.MyWorkerMethods.GetPersonJson", []);
    

    to

    var personJson = await worker.InvokeAsync<string>("BlazorWasmApp.Workers.MyWorkerMethods.GetPersonJson", []);
    var person = JsonSerializer.Deserialize<Person>(personJson)!;
    

    ?

    The screenshot you posted contains the stack with InvokeAsync<Person>which is the code before the instruction update.

  11. jinzhao1127 commented on Apr 22, 2026

    @jinzhao1127
    Author

    Exactly, deserialization is now required. @jinzhao1127 are you sure you changed

    @ilonatommy Oh, sorry, I hadn't realized that earlier. I've updated the code, and it's working fine now.

    Image
  12. jinzhao1127 commented on Apr 24, 2026

    @jinzhao1127
    Author

    Close this bug as fixed.

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

Metadata

Metadata

Assignees

Labels

area-blazorbug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions