dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.86k stars 670 forks source link

Debugger Doesn't Pause on Exceptions in `.razor` when justMyCode is false #3895

Open arsinclair opened 4 years ago

arsinclair commented 4 years ago

Issue Description

Debugger doesn't pause on exceptions in .razor files when justMyCode setting is set to false.

Steps to Reproduce

Just download the demo project DemoTheProblem.zip

Or follow the steps below:

Preparation

  1. Create a Demo Project dotnet new blazorserver -o BlazorServer --auth Individual
  2. Add Entity.cs class under BlazorServer/Data
using System.Collections.Generic;

namespace BlazorServer.Data
{
    public class Entity
    {
        public Dictionary<string, Field> Fields { get; set; }
    }

    public class Field
    {
        public object Value { get; set; }
    }
}
  1. Open BlazorServer/Pages/Counter.razor and make following modifications Add the following variables to @code block
    public string entityName = "contact";
    public string selectedId = "asdasd";  
    public string searchFieldName = "asdasd";
    private Entity selectedEntity;

    Add the following razor code to the page

    @if (selectedId != null && !string.IsNullOrEmpty(selectedId) && !string.IsNullOrEmpty(entityName))
    {
    <div>@selectedEntity.Fields.FirstOrDefault().Value.ToString()</div>
    }

    This code should throw an exception, because selectedEntity is never set.

  2. Finally, generate a debug config (launch.json) by pressing F5 and selecting .NET Core Clr
  3. Add the following line into configurations section: "justMyCode": true,

Reproduction

  1. Run the application, switch to Counter page in the Left Sidebar menu and observe VSCode pausing on exception image
  2. Go to launch.json and change "justMyCode": true, to "justMyCode": false,
  3. Repeat 1, and observe that instead of pausing on exception, VSCode will just log it into the Debug Console. image

In the breakpoints section, All Exceptions is unticked, and User-Unhandled Exceptions is ticked.

Expected Behavior

I think VSCode should break on any unhandled exception, just like Visual Studio. It is strange that this behaviour is bound to justMyCode setting. Maybe I am doing something wrong?

This problem somehow reminds me about #3369

Logs

OmniSharp log

Starting OmniSharp server at 07/07/2020, 04:21:47 Target: /home/jrm/GIT/DemoTheProblem OmniSharp server started. Path: /home/jrm/.vscode/extensions/ms-dotnettools.csharp-1.22.1/.omnisharp/1.35.3/run PID: 17756 [info]: OmniSharp.Stdio.Host Starting OmniSharp on debian 10.0 (x64) [info]: OmniSharp.Services.DotNetCliService DotNetPath set to dotnet [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Located 1 MSBuild instance(s) 1: StandAlone 16.4 - "/home/jrm/.vscode/extensions/ms-dotnettools.csharp-1.22.1/.omnisharp/1.35.3/omnisharp/.msbuild/Current/Bin" [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator MSBUILD_EXE_PATH environment variable set to '/home/jrm/.vscode/extensions/ms-dotnettools.csharp-1.22.1/.omnisharp/1.35.3/omnisharp/.msbuild/Current/Bin/MSBuild.dll' [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Registered MSBuild instance: StandAlone 16.4 - "/home/jrm/.vscode/extensions/ms-dotnettools.csharp-1.22.1/.omnisharp/1.35.3/omnisharp/.msbuild/Current/Bin" CscToolExe = csc.exe MSBuildToolsPath = /home/jrm/.vscode/extensions/ms-dotnettools.csharp-1.22.1/.omnisharp/1.35.3/omnisharp/.msbuild/Current/Bin CscToolPath = /home/jrm/.vscode/extensions/ms-dotnettools.csharp-1.22.1/.omnisharp/1.35.3/omnisharp/.msbuild/Current/Bin/Roslyn BypassFrameworkInstallChecks = true MSBuildExtensionsPath = /home/jrm/.vscode/extensions/ms-dotnettools.csharp-1.22.1/.omnisharp/1.35.3/omnisharp/.msbuild [info]: OmniSharp.Cake.CakeProjectSystem Detecting Cake files in '/home/jrm/GIT/DemoTheProblem'. [info]: OmniSharp.Cake.CakeProjectSystem Could not find any Cake files [info]: OmniSharp.MSBuild.ProjectSystem No solution files found in '/home/jrm/GIT/DemoTheProblem' [info]: OmniSharp.MSBuild.ProjectManager Queue project update for '/home/jrm/GIT/DemoTheProblem/BlazorServer/BlazorServer.csproj' [info]: OmniSharp.Script.ScriptProjectSystem Detecting CSX files in '/home/jrm/GIT/DemoTheProblem'. [info]: OmniSharp.Script.ScriptProjectSystem Could not find any CSX files [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0 [info]: OmniSharp.MSBuild.ProjectManager Loading project: /home/jrm/GIT/DemoTheProblem/BlazorServer/BlazorServer.csproj [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100 [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110 [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140 [info]: OmniSharp.WorkspaceInitializer Configuration finished. [info]: OmniSharp.Stdio.Host Omnisharp server running using Stdio at location '/home/jrm/GIT/DemoTheProblem' on host 17647. [info]: OmniSharp.OmniSharpWorkspace Miscellaneous file: /home/jrm/GIT/DemoTheProblem/BlazorServer/Pages/Counter.razor__virtual.cs added to workspace [info]: OmniSharp.MSBuild.ProjectManager Successfully loaded project file '/home/jrm/GIT/DemoTheProblem/BlazorServer/BlazorServer.csproj'. [info]: OmniSharp.MSBuild.ProjectManager Adding project '/home/jrm/GIT/DemoTheProblem/BlazorServer/BlazorServer.csproj' [info]: OmniSharp.MSBuild.ProjectManager Update project: BlazorServer

C# log

It is empty

Environment information

VSCode version: 1.46.1 C# Extension: 1.22.1

Mono Information OmniSharp using built-in mono
Dotnet Information .NET Core SDK (reflecting any global.json): Version: 3.1.301 Commit: 7feb845744 Runtime Environment: OS Name: debian OS Version: 10 OS Platform: Linux RID: debian.10-x64 Base Path: /usr/share/dotnet/sdk/3.1.301/ Host (useful for support): Version: 3.1.5 Commit: 65cd789777 .NET Core SDKs installed: 3.1.301 [/usr/share/dotnet/sdk] .NET Core runtimes installed: Microsoft.AspNetCore.App 3.1.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.5 [/usr/share/dotnet/shared/Microsoft.NETCore.App] To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download
Visual Studio Code Extensions |Extension|Author|Version| |---|---|---| |auto-using|Fudge|0.7.15| |blazorsnippets|ScottSauber|1.3.0| |csharp|ms-dotnettools|1.22.1| |vscode-css-formatter|aeschli|1.0.1| |vscode-peacock|johnpapa|3.7.2| |yarn-ui|xqchen|0.1.2|;
gregg-miskelly commented 4 years ago

@arsinclair What you are describing sounds expected -- the debugger stops with justMyCode enabled because the exception was "user unhandled" (the exception travelled through your code and was caught by library code). If you turn off Just-My-Code then there is no such thing as user code and therefore there is no such thing as user-unhandled. Since the framework is catching your exception the only way to stop on it is to break on all thrown exceptions.

arsinclair commented 4 years ago

I am transitioning from VS to VS Code and might not be familiar with how things are, so please correct me if I am wrong.

In my understanding, if I turn on All Exceptions the IDE will pause on all exceptions, including those that are 'try-caught' by the code. And if I use User-Unhandled Exceptions but not All Exceptions, I would imagine that I should see all exceptions, except those that are 'try-caught'. Am I right here?

I understand with your last comment that this problem probably shifts now to a different domain, that is not related to OmniSharp, so if this is the matter, please feel free to point it out.

My case with the debugging configuration is the following: there's my code that throws exceptions and I want to pause on them (this is a legit reason to use justMyCode = true), however there's also bunch of vendor code that throws exceptions I want to pause on, which are not propagated if justMyCode = true.

So how can I achieve what I want?