dotnet / dotnet/vscode-csharp

Using the C# Debugger shows different Views than when using dotnet run

Open
#9,554 1 comment 0 reactions 0 assignees View on GitHub
Debugger untriaged
Dominant language
TypeScript
Stars
3.1k
Forks
737
Avg merge
18h 40m
Merged PRs (30d)
31

Description

## Environment data
.NET SDK:
Version: 10.0.300
Commit: caa81fa497
Workload version: 10.0.300-manifests.b47d7e23
MSBuild version: 18.6.3+caa81fa49

Runtime Environment:
OS Name: org.freedesktop.platform
OS Version: 25.08
OS Platform: Linux
RID: linux-x64
Base Path: /usr/lib/sdk/dotnet10/lib/sdk/10.0.300/

.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
Version: 10.0.8
Architecture: x64
Commit: 94ea82652c

.NET SDKs installed:
10.0.300 [/usr/lib/sdk/dotnet10/lib/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 10.0.8 [/usr/lib/sdk/dotnet10/lib/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 10.0.8 [/usr/lib/sdk/dotnet10/lib/shared/Microsoft.NETCore.App]

## Steps to reproduce

1) Project Setup

- Create a new MVC Project with Authentication enabled. Choose Individual Accounts for type.
- Scaffold the Register.cshtml page for a custom User class that inherits from IdentityUser by using the steps described in the official documentation for scaffolding Account pages.
- Make sure this User class has additional fields like First Name and Last Name
- Open the Register.cshtml page and add the additional fields for First Name and Last Name
- Open Register.cshtml.cs and expand Input to include the new fields.
- Set the First Name and Last Name fields in the custom User class in OnPostAsync in Register.cshtml.cs

2) Debugger Setup

- Create the launch.json file in .vscode
- Use the default .NET Core Launch (Web) setup
- Change the "program" path to the .dll file.

Debugging

- Debug the program, the View Index cannot be found.
- Stop the Debugger and update program.cs by adding RazorRuntimeCompilation to the Services (needs NuGet Package)
- Debug the Program again. Views work now. Navigate to the Register page.
- The View is still the standard Register View and not the scaffolded version with the additional fields.
- Stop the debugger and open the terminal. Type `dotnet run` and press enter
- Navigate to the Register page and notice it now displays the correct View with the fields for First Name and Last Name.

## Expected behavior
- Using both `dotnet run` and the Debugger should show the same results in Views

## Actual behavior
- Running the app with the Debugger shows different Views. The first image is using the Debugger. The second is when using `dotnet run`

Image

Image

## Additional context
- Similar issues occur when trying to use .resx files for translations. Using a ViewLocalizer in a Razor page will only display the Values when using `dotnet run`. With the debugger, it simply displays the Keys as the .resx files appear to not be loaded / compiled when using the debugger.
- This version of VS Code runs in a container, but it has full access to all files outside the container and the problem persists.

Contributor guide

Open the contributing guide

Research direction

Start by comparing the default .vscode/launch.json debugger configuration with the terminal `dotnet run` path, then inspect how the debugger handles program.cs, Register.cshtml, Register.cshtml.cs, and the related views and .resx files. Done means the debugger and `dotnet run` load the same scaffolded views, fields, and localized values.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, vscode
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.