Skip to content

After setting breakpoints and then debugging the Web Worker With Blazor WASM apps, the breakpoints are not hit #65823

@EmilyFeng97

Description

@EmilyFeng97

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

  • 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 :
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    Also add:

    <ItemGroup>
      <SupportedPlatform Include="browser" />
    </ItemGroup>
    
  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
    
    <h3>WebWorker Demo</h3>
    <button @onclick="InitAndTest">Test WebWorker</button>
    <p>Status: @status</p>
    <p>Add result: @addResult</p>
    <p>Greet result: @greetResult</p>
    <p>JSON result: @jsonResult</p>
    
    @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<int>("BlazorWasmApp.Workers.MyWorkerMethods.Add", [5, 3]);
            addResult = sum.ToString();
    
            var greeting = await worker.InvokeAsync<string>("BlazorWasmApp.Workers.MyWorkerMethods.Greet", ["World"]);
            greetResult = greeting;
    
            var person = await worker.InvokeAsync<Person>("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.
  2. This issue does not repro when debugging if I don't set any breakpoints.
  3. This issue does not repro when Ctrl + F5.

Actual Result
The WebWorker hang when debugging Blazor WASM apps in VS
Image

Error Log

Metadata

Metadata

Assignees

Labels

area-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.feature-blazor-debuggingThis issue is related to debugging of Blazor WebAssembly apps

Type

No fields configured for Bug.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions