dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.88k stars 676 forks source link

Unable to debug project code invoked by a nuget package using `Activator.CreateInstance` #4945

Closed eduherminio closed 2 years ago

eduherminio commented 2 years ago

Issue Description

Unable to debug code from my project invoked by a nuget package using Activator.CreateInstance. This works as expected in VS.

Library code example:

        public static void SolveLast()
        {
                    var lastProblem = LoadAllProblems(Assembly.GetEntryAssembly()!).LastOrDefault();
                    if (lastProblem is not null)
                    {
                        var potentialProblem = Activator.CreateInstance(lastProblem);
                        if (potentialProblem is BaseProblem problem)
                        {
                              var result1 = await potentialProblem.Solve_1();
                              var result2 = await potentialProblem.Solve_2();
                        }
                    }
         }

        private static IEnumerable<Type> LoadAllProblems(Assembly assembly)
        {
            return assembly.GetTypes()
                .Where(type => typeof(BaseProblem).IsAssignableFrom(type) && !type.IsInterface && !type.IsAbstract);
        }

Project code (from where SolveLast() method is invoked:

    public class Day_01 : BaseProblem
    {
        public override ValueTask<string> Solve_1() => new("Solution 1");

        public override ValueTask<string> Solve_2() => new("Solution 2");
    }

Steps to Reproduce

Library/nuget package I'm experiencing this issue with: AoCHelper

Expected Behavior

Actual Behavior

Logs

OmniSharp log

Post the output from Output-->OmniSharp log here

C# log

Post the output from Output-->C# here

Environment information

VSCode version: 1.62.3 C# Extension: 1.23.17

Dotnet Information .NET SDK (reflecting any global.json): Version: 6.0.100 Commit: 9e8b04bbff Runtime Environment: OS Name: Windows OS Version: 10.0.19042 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\6.0.100\ Host (useful for support): Version: 6.0.0 Commit: 4822e3c3aa .NET SDKs installed: 3.1.118 [C:\Program Files\dotnet\sdk] 3.1.415 [C:\Program Files\dotnet\sdk] 5.0.209 [C:\Program Files\dotnet\sdk] 6.0.100 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.21 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.21 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download
Visual Studio Code Extensions |Extension|Author|Version| |---|---|---| |cpptools|ms-vscode|1.7.1| |csharp|ms-dotnettools|1.23.17| |dotnet-test-explorer|formulahendry|0.7.7| |markdown-preview-github-styles|bierner|0.2.0| |rainbow-brackets|2gua|0.0.6| |remote-containers|ms-vscode-remote|0.205.2| |remote-wsl|ms-vscode-remote|0.58.5| |vs-keybindings|ms-vscode|0.2.1| |vscode-docker|ms-azuretools|1.18.0| |vscode-markdownlint|DavidAnson|0.45.0|;
WardenGnaw commented 2 years ago

It seems like Spectre.Console.dll throws an exception when using "console": "internalConsole" in your launch.json since it is not a real terminal.

image

If you switch to "console": "integratedTerminal" or "console": "externalTerminal", Spectre.Console will not throw an exception and you should be able to hit your breakpoint.

image

I hope you will be able to Debug with VS Code for Day 11 (and onwards) of AoC 2021.

eduherminio commented 2 years ago

Awesome, thx @WardenGnaw!