vscode-csharp icon indicating copy to clipboard operation
vscode-csharp copied to clipboard

NullReferenceException when Debug NUnit test

Open PiotrNestor opened this issue 3 years ago • 0 comments

Issue Description

In a NUnit test project for Petstore API The API client is generated with NSwagStudio from the Petstore API Json definition.

Running 'Debug' results in NullReferenceException in OmniSharp.DotNetTest.VSTestManager.DebugGetStartInfoAsync

The test project Petstore.zip

Steps to Reproduce

Test example:

using System.Threading.Tasks;

namespace Tests;

public class Tests
{
    Client client;

    [SetUp]
    public void Setup()
    {
        client = new Petstore.Client(new System.Net.Http.HttpClient());
        client.BaseUrl = "http://localhost/v2";
    }

    [TestCase(TestName = "Petstore_GetInventory")]
    public async Task GetInventory()
    {
        var result = await client.GetInventoryAsync();
        Assert.That(result.Count, Is.Not.Zero);
    }
}
  1. 'Debug' test GetInventory
  2. OmniSharp TestManager fails

Expected Behavior

It should be possible to debug / run the test

Actual Behavior

Logs

Failed to start debugger: "System.NullReferenceException: Object reference not set to an instance of an object.\r\n at OmniSharp.DotNetTest.VSTestManager.DebugGetStartInfoAsync(String[] methodNames, String runSettings, String testFrameworkName, String targetFrameworkVersion, CancellationToken cancellationToken) in D:\a\1\s\src\OmniSharp.DotNetTest\VSTestManager.cs:line 170\r\n at OmniSharp.Endpoint.EndpointHandler2.GetFirstNotEmptyResponseFromHandlers(ExportHandler2[] handlers, TRequest request) in D:\a\1\s\src\OmniSharp.Host\Endpoint\EndpointHandler.cs:line 201\r\n at OmniSharp.Endpoint.EndpointHandler2.HandleRequestForLanguage(String language, TRequest request, RequestPacket packet) in D:\\a\\1\\s\\src\\OmniSharp.Host\\Endpoint\\EndpointHandler.cs:line 230\r\n at OmniSharp.Endpoint.EndpointHandler2.Process(RequestPacket packet, LanguageModel model, JToken requestObject) in D:\a\1\s\src\OmniSharp.Host\Endpoint\EndpointHandler.cs:line 131\r\n at OmniSh...

OmniSharp log

{ "Request_seq": 30, "Command": "/v2/debugtest/getstartinfo", "Running": true, "Success": false, "Message": ""System.NullReferenceException: Object reference not set to an instance of an object.\r\n at OmniSharp.DotNetTest.VSTestManager.DebugGetStartInfoAsync(String[] methodNames, String runSettings, String testFrameworkName, String targetFrameworkVersion, CancellationToken cancellationToken) in D:\\a\\1\\s\\src\\OmniSharp.DotNetTest\\VSTestManager.cs:line 170\r\n at OmniSharp.Endpoint.EndpointHandler2.GetFirstNotEmptyResponseFromHandlers(ExportHandler2[] handlers, TRequest request) in D:\\a\\1\\s\\src\\OmniSharp.Host\\Endpoint\\EndpointHandler.cs:line 201\r\n at OmniSharp.Endpoint.EndpointHandler2.HandleRequestForLanguage(String language, TRequest request, RequestPacket packet) in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Host\\\\Endpoint\\\\EndpointHandler.cs:line 230\\r\\n at OmniSharp.Endpoint.EndpointHandler2.Process(RequestPacket packet, LanguageModel model, JToken requestObject) in D:\\a\\1\\s\\src\\OmniSharp.Host\\Endpoint\\EndpointHandler.cs:line 131\r\n at OmniSharp.Stdio.Host.HandleRequest(String json, ILogger logger) in D:\\a\\1\\s\\src\\OmniSharp.Stdio\\Host.cs:line 218"", "Body": null, "Seq": 288, "Type": "response" }

C# log

Post the output from Output-->C# here

Environment information

VSCode version: 1.71.0 C# Extension: 1.25.0

Dotnet Information .NET SDK (reflecting any global.json): Version: 6.0.400 Commit: 7771abd614

Runtime Environment: OS Name: Windows OS Version: 10.0.19044 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\6.0.400\

global.json file: Not found

Host: Version: 6.0.9 Architecture: x64 Commit: 163a63591c

.NET SDKs installed: 6.0.304 [C:\Program Files\dotnet\sdk] 6.0.400 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Download .NET: https://aka.ms/dotnet-download

Learn about .NET Runtimes and SDKs: https://aka.ms/dotnet/runtimes-sdk-info

Visual Studio Code Extensions
Extension Author Version
asciidoctor-vscode asciidoctor 2.9.8
csharp ms-dotnettools 1.25.0
dotnet-test-explorer formulahendry 0.7.7
gauge getgauge 0.1.0
jupyter ms-toolsai 2022.8.1002431955
jupyter-keymap ms-toolsai 1.0.0
jupyter-renderers ms-toolsai 1.0.9
python ms-python 2022.14.0
remote-wsl ms-vscode-remote 0.66.3
spellright ban 3.0.90
test-adapter-converter ms-vscode 0.1.6
trailing-spaces shardulm94 0.4.1
visual-nuget fullstackspider 0.2.1
vscode-groovy-lint NicolasVuillamy 2.0.0
vscode-nuget-package-manager jmrog 1.1.6
vscode-pylance ms-python 2022.9.20
vscode-python-test-adapter littlefoxteam 0.7.1
vscode-test-explorer hbenl 2.21.1

PiotrNestor avatar Sep 16 '22 11:09 PiotrNestor