aws / aws-sam-cli-app-templates

Apache License 2.0
475 stars 260 forks source link

omnisharp.json msbuild rhel.7.2-x64 prevents unit tests debugging in VS Code #316

Closed russau closed 1 year ago

russau commented 1 year ago

This line is making unit tests in Visual Studio Code fail to debug. When I remove the msbuild setting and reload the window my unit tests work. Does this setting need to be here? Without it I'm able to sam build and sam deploy okay.

https://github.com/aws/aws-sam-cli/blob/bad9a6226d0b871bf531ba649ee12a6ca90aa984/samcli/lib/init/templates/cookiecutter-aws-sam-hello-dotnet/%7B%7Bcookiecutter.project_name%7D%7D/omnisharp.json#L9

The error happens when you open the project from the directory that has omnisharp.json in the root (like below), and attempt to debug a unit test. I can supply a repro project if that helps.

.
├── README.md
├── events
│   └── event.json
├── omnisharp.json
├── samconfig.toml
├── src
│   └── Stars
│       ├── Function.cs
│       ├── Stars.csproj
│       └── aws-lambda-tools-defaults.json
├── template.yaml
└── test
    └── Stars.Test
        ├── FunctionTest.cs
        └── Stars.Tests.csproj

image

In the omnisharp logs I see the error below:

        ************ Request ************
{
  "Type": "request",
  "Seq": 29,
  "Command": "/v2/debugtest/getstartinfo",
  "Arguments": {
    "FileName": "/Users/sayersr/TestingZone/dev-course-samples/dotnet-sam-app/test/Stars.Test/FunctionTest.cs",
    "MethodName": "Stars.Tests.FunctionTest.TestStarsFunctionHandler",
    "TestFrameworkName": "xunit",
    "TargetFrameworkVersion": ".NETCoreApp,Version=v6.0",
    "NoBuild": false
  }
}
[fail]: OmniSharp.Stdio.Host
        ************  Response (3308.9681ms) ************ 
{
  "Request_seq": 29,
  "Command": "/v2/debugtest/getstartinfo",
  "Running": true,
  "Success": false,
  "Message": "\"System.InvalidOperationException: The debugger could not be started\\n   at OmniSharp.DotNetTest.Services.DebugTestService.Handle(DebugTestGetStartInfoRequest request) in /Users/runner/work/1/s/src/OmniSharp.DotNetTest/Services/DebugTestService.cs:line 42\\n   at OmniSharp.Endpoint.Exports.RequestHandlerExportHandler`2.Handle(TRequest request) in /Users/runner/work/1/s/src/OmniSharp.Host/Endpoint/Exports/RequestHandlerExportHandler.cs:line 29\\n   at OmniSharp.Endpoint.EndpointHandler`2.GetFirstNotEmptyResponseFromHandlers(ExportHandler`2[] handlers, TRequest request) in /Users/runner/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 197\\n   at OmniSharp.Endpoint.EndpointHandler`2.HandleRequestForLanguage(String language, TRequest request, RequestPacket packet) in /Users/runner/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 233\\n   at OmniSharp.Endpoint.EndpointHandler`2.Process(RequestPacket packet, LanguageModel model, JToken requestObject) in /Users/runner/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 142\\n   at OmniSharp.Stdio.Host.HandleRequest(String json, ILogger logger) in /Users/runner/work/1/s/src/OmniSharp.Stdio/Host.cs:line 258\"",
  "Body": null,
  "Seq": 280,
  "Type": "response"
}
lucashuy commented 1 year ago

Hi, thanks for raising this issue! I can replicate your behaviour with the hello world template and was also able to get the debugger to run by removing that property in the omnisharp.json file like you suggested.

Let me take a look around to see if there are any side effects from removing that property from our templates, or if there is anything we can do to improve this.

lucashuy commented 1 year ago

Hi, sorry about the lack of updates regarding this. For those that may be experiencing this issue, please double check that mono is installed on your system. Depending on OS type, version and .NET SDK versions, mono may not come bundled when installing other prerequisites. Please reopen this or create a new issue if there are any further developments or problems.