Repository navigation
Closed
Labels
area-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.
Milestone
Description
REGRESSION INFO: Works well on 11.0 Preview 3
INSTALL STEPS
- Clean Win11 x64 23h2 ENU
- Install the .NET 11.0 preview 4
- Apply feed
Platform
- Windows
- macOS
- Linux
Repro Steps
- Open a normal Command Prompt
- Create a Blazor WebAssembly Standalone App with a WebWorker library
dotnet new blazorwasm -n MyApp
dotnet new blazorwebworker -n MyWebWorker
- Add a project reference from the Blazor app to the WebWorker library:
cd MyApp
dotnet add reference ../MyWebWorker/MyWebWorker.csproj
-
Open .csproj of Blazor WebAssembly app and add the following inside the existing :
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> -
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);
}- 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", []);
}
}-
Install the dotnet-serve tool
dotnet tool install --global dotnet-serve -
Publish the application to folder:
dotnet publish -c Release -
Go to the publish output directory and run dotnet-serve -S:
cd bin\Release\net11.0\publish\wwwroot
dotnet-serve -S
- Open a browser and navigate to the URL
Note:
- This issue does not repro when dotnet run
- I notices that the
webworkertemplate change toblazorwebworker
Actual Result
An unhandled error has occurred.
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)Metadata
Metadata
Assignees
Labels
area-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.
Activity
jinzhao1127 commentedon Apr 17, 2026
@ilonatommy, could you look at this bug?
github-actions commentedon Apr 17, 2026
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>>throwsDeserializeUnableToConvertValuewhen running a published WASM app with a WebWorker, but works fine withdotnet run.Regression Info
worker.InvokeAsync<List<T>>call successfully deserializes the JSON-serialized return value in Preview 3, but fails with aJsonException(DeserializeUnableToConvertValue) in Preview 4. The issue only reproduces when the app is published (notdotnet run), suggesting the regression may be related to trimming/AOT/linker metadata changes between previews.Potential Duplicates
Notes
Microsoft.JSInterop.JSRuntime.EndInvokeJSfailing to deserialize the return value — the JSON content is a valid serializedList<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 forList<T>in the published output.dotnet run(no publishing/trimming involved), which strongly points to a publish-time trim annotation or AOT metadata issue.ilonatommy commentedon Apr 17, 2026
@jinzhao1127, can you use this instruction: https://github.com/dotnet/AspNetCore-ManualTests/pull/3739 and let me know if it works?
jinzhao1127 commentedon Apr 20, 2026
@ilonatommy , Yes this issue also reproduces on the instruction https://github.com/dotnet/AspNetCore-ManualTests/pull/3739,
KristofferStrube commentedon Apr 20, 2026
I can replicate this in ASP.NET Core 11 Preview 4, using
dotnet runas 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.
ilonatommy commentedon Apr 22, 2026
Exactly, deserialization is now required. @jinzhao1127 are you sure you changed
to
?
The screenshot you posted contains the stack with
InvokeAsync<Person>which is the code before the instruction update.jinzhao1127 commentedon Apr 22, 2026
@ilonatommy Oh, sorry, I hadn't realized that earlier. I've updated the code, and it's working fine now.
jinzhao1127 commentedon Apr 24, 2026
Close this bug as fixed.