After setting breakpoints and then debugging the Web Worker With Blazor WASM apps, the breakpoints are not hit
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
**REGRESSION INFO** No, web worker is a new feature introduced in Preview 2. Also repro on 11.0 Preview 3
**INSTALL STEPS**
1. Clean Win11 x64 23h2 ENU
2. Install the latest VS 18.5 Insider 2
3. Install the latest .NET 11.0 preview 2 SDK
**Platform**
- [x] Windows
- [ ] macOS
- [ ] Linux
**Repro Steps**
1. File > New Project > Select "Blazor WebAssembly Standalone App" > Give name "BlazorWasmApp" > Next > select ".NET 11.0" > Create
2. Right-click the Solution > Add > New Project > Select ".NET Web Worker" template > Give name "WorkerLib" > Create
3. Right-click the BlazorWasmApp project > Add > Project Reference > Check WorkerLib > OK
4. Open BlazorWasmApp.csproj and add inside :
`true`
Also add:
```
```
5. Create a new file Workers/MyWorkerMethods.cs with the following content:
```
using System.Runtime.InteropServices.JavaScript;
using System.Runtime.Versioning;
using System.Text.Json;
namespace BlazorWasmApp.Workers;
[SupportedOSPlatform("browser")]
public static partial class MyWorkerMethods
{
[JSExport]
public static int Add(int a, int b) => a + b;
[JSExport]
public static string Greet(string name) => $"Hello, {name}!";
[JSExport]
public static string GetPersonJson()
=> JsonSerializer.Serialize(new { Name = "Alice", Age = 30 });
}
public record Person(string Name, int Age);
```
6. Open `Pages/Home.razor ` and add the following code below the existing content:
```
@using WorkerLib
@using BlazorWasmApp.Workers
@inject IJSRuntime JSRuntime
@implements IAsyncDisposable
WebWorker Demo
Test WebWorker
Status: @status
Add result: @addResult
Greet result: @greetResult
JSON result: @jsonResult
@code {
private WebWorkerClient? worker;
private string status = "Not started";
private string addResult = "", greetResult = "", jsonResult = "";
private async Task InitAndTest()
{
status = "Initializing...";
worker = await WebWorkerClient.CreateAsync(JSRuntime);
status = "Ready";
var sum = await worker.InvokeAsync("BlazorWasmApp.Workers.MyWorkerMethods.Add", [5, 3]);
addResult = sum.ToString();
var greeting = await worker.InvokeAsync("BlazorWasmApp.Workers.MyWorkerMethods.Greet", ["World"]);
greetResult = greeting;
var person = await worker.InvokeAsync("BlazorWasmApp.Workers.MyWorkerMethods.GetPersonJson", []);
jsonResult = $"{person.Name}, Age {person.Age}";
}
public async ValueTask DisposeAsync()
{
if (worker != null) await worker.DisposeAsync();
}
}
```
7. Place a breakpoint at the `addResult = sum.ToString(); `line in Pages/Home.razor
8. Run the project (F5).
9. After the webpage loads successfully, click the Test WebWorker button
**Note:**
1. This issue also repro when place the breakpoint in MyWorkerMethods.cs file.
1. This issue does not repro when debugging if I don't set any breakpoints.
2. This issue does not repro when Ctrl + F5.
**Actual Result**
The WebWorker hang when debugging Blazor WASM apps in VS
**Error Log**
Contributor guide
Assessment
This issue has not been assessed yet.