dotnet / razor

Compiler and tooling experience for Razor ASP.NET Core apps in Visual Studio, Visual Studio for Mac, and VS Code.
https://asp.net
MIT License
491 stars 190 forks source link

Breakpoint is not hit in razor page of Blazor WebAssembly project, if the code is separated from razor page #6816

Closed aDisplayName closed 1 year ago

aDisplayName commented 2 years ago

Describe the bug: Breakpoint in razor page is not being hit in Blazor WebAssembly project, if the code is separated from razor page

Version used:

Microsoft Visual Studio Enterprise 2022 Version 17.3.3 VisualStudio.17.Release/17.3.3+32825.248 Microsoft .NET Framework Version 4.8.04084

Installed Version: Enterprise

ASP.NET and Web Tools 17.3.376.3011 ASP.NET and Web Tools

Azure App Service Tools v3.0.0 17.3.376.3011 Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools 17.3.376.3011 Azure Functions and Web Jobs Tools

C# Tools 4.3.0-3.22423.10+b35bb0baca1071d50cc4f8cf5a1a89e7cc112461 C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Markdown Editor v2 2.0.130 A full featured Markdown editor with live preview and syntax highlighting. Supports GitHub flavored Markdown.

Microsoft Azure Tools for Visual Studio 2.9 Support for Azure Cloud Services projects

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

NuGet Package Manager 6.3.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Razor (ASP.NET Core) 17.0.0.2232702+e1d654e792aa2fe6646a6935bcca80ff0aff4387 Provides languages services for ASP.NET Core Razor.

REST API Client Code Generator 1.0

SQL Server Data Tools 17.0.62207.04100 Microsoft SQL Server Data Tools

TypeScript Tools 17.0.10701.2001 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.3.0-3.22423.10+b35bb0baca1071d50cc4f8cf5a1a89e7cc112461 Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 17.1.0-beta.22363.4+1b94f89d4d1f41f20f9be73c76f4b229d4e49078 Microsoft Visual F# Tools

Visual Studio IntelliCode 2.2 AI-assisted development for Visual Studio.

WiX Toolset Visual Studio Extension 1.0.0.18 WiX Toolset Visual Studio Extension version 1.0.0.18 Copyright (c) .NET Foundation and contributors. All rights reserved.

To reproduce:

  1. Create new Blazor WebAssembly project, selected "ASP.NET Core hosted"

    image

  2. Change the code of Pages/Counter.razor to the following

    @page "/counter"
    
    <PageTitle>Counter</PageTitle>
    
    <h1>Counter</h1>
    
    <p role="status">Current count: @currentCount</p>
    @if ((currentCount % 2) == 1)
    {
       <p>Odd</p>
    }
    else
    {
       <p>Even</p>
    }
    <button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
    
    @code{
    
       private int currentCount = 0;
    
       private void IncrementCount()
       {
           currentCount++;
       }
    
    }
  3. Set a breakpoint on line @if ((currentCount % 2) == 1), as well as currentCount++, and hit F5 to start Debug session.

  4. Both breakpoints will be hit.

    image

  5. Remove section @code{}.

  6. Create a new file: Pages/Counter.razor.cs with following content

    namespace BlazorApp1.Client.Pages
    {
       public partial class Counter
       {
           private int currentCount = 0;
    
           private void IncrementCount()
           {
               currentCount++;
           }
       }
    }
  7. Hit F5 to start debug session, the breakpoint in Pages/Counter.razor will not be hit, while the one in Pages/Counter.razor.cs will still be hit. image

Expected behavior: Both breakpoints in Pages/Counter.razor and Pages/Counter.razor.cs should be hit.

Actual behavior: The breakpoint in Pages/Counter.razor will not be hit, while the one in Pages/Counter.razor.cs will still be hit. Additional context: Add any other context about the problem here.

davidwengier commented 1 year ago

I can repro this in 17.3.4, but it doesn't repro in 17.4.0 Preview 2.1

I suspect a runtime and/or debugger change has fixed this, and not us, but either way I'm going to close this as fixed.