vstest icon indicating copy to clipboard operation
vstest copied to clipboard

Debugging XUnit test cases fails critically

Open srivatsn opened this issue 9 years ago • 32 comments

From @couven92 on February 24, 2017 10:45

Ref.: https://github.com/Microsoft/VSProjectSystem/issues/195 Originally issued in wrong repository

Here's my CSPROJ:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
    <RuntimeFrameworkVersion>1.1.0</RuntimeFrameworkVersion>
  </PropertyGroup>
  <PropertyGroup Label="BasePath">
    <BaseOutputPath>$(SolutionDir)bin\</BaseOutputPath>
    <BaseIntermediateOutputPath>$(SolutionDir)obj\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170222-09" />
    <PackageReference Include="xunit" Version="2.2.0" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
  </ItemGroup>
</Project>

Note the (as of writing this issue) the newest versions for the Test SDK and XUnit packages. I'm using the newest RC for Visual Studio 2017 (Version 15.0.0-RC4+26206.0)

Also note that I'm setting the BaseOutputPath and BaseIntermediateOutputPath to values different from their defaults.

Running test cases from the Test Explorer view in Visual Studio works fine. However, when I choose to debug one or more tests, Visual Studio goes over into debugging mode, and immediately displays a crtical error message window:

A fatal error has occurred and debugging needs to be terminated. For more details, please see the Microsoft Help and Support web site. HRESULT=0x8000ffff. ErrorCode=0x0.

Copied from original issue: dotnet/roslyn-project-system#1620

srivatsn avatar Mar 01 '17 21:03 srivatsn

From @dmenoud on February 27, 2017 15:27

I have the same problem. Running its ok, but debugging crash.

Microsoft Visual Studio Professional 2017 RC Version 15.0.26206.0

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
    <DebugType>portable</DebugType>
    <AssemblyName>BtimeServer.Engine.Tests</AssemblyName>
    <PackageId>BtimeServer.Engine.Tests</PackageId>
    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
    <PackageTargetFallback>$(PackageTargetFallback);dotnet5.4;portable-net451+win8</PackageTargetFallback>
    <RuntimeFrameworkVersion>1.1.0</RuntimeFrameworkVersion>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\..\src\BtimeServer.Common\BtimeServer.Common.csproj" />
    <ProjectReference Include="..\..\src\BtimeServer.Data\BtimeServer.Data.csproj" />
    <ProjectReference Include="..\..\src\BtimeServer.Engine\BtimeServer.Engine.csproj" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="1.1.0" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
    <PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
    <PackageReference Include="xunit" Version="2.2.0" />
    <PackageReference Include="System.Runtime.Serialization.Primitives" Version="4.3.0" />
  </ItemGroup>

</Project>

image

srivatsn avatar Mar 01 '17 21:03 srivatsn

By any chance is there a launchSettings.json for this project? We've seen this issue earlier when launchSettings.json was pointing to an incorrect path.

codito avatar Mar 02 '17 04:03 codito

Hmm... I wanted to give you a launchSettings.json (because I hvae had problems with that one before as well), but I discovered that I don't have any launchSettings.json for the test project.

fredrikhr avatar Mar 02 '17 09:03 fredrikhr

Had the same problem, for me removing launchSettings.json fixed it!

flagbug avatar Mar 21 '17 16:03 flagbug

Would be nice if my problem could be solved as simple as that. But I have no launchSettings.json that I could delete! And it still does not work at my end...

fredrikhr avatar Mar 21 '17 17:03 fredrikhr

Have you got any other test adapter installed? I had the same problem, for me disabling the NUnit adapter fixed it.

cobyzeng avatar Mar 21 '17 22:03 cobyzeng

I had the same error, no launchSettings.json file present and no other adapters. I'm not sure exactly what fixed the problem but I did a couple of things. I closed VS 2017, ran the test on the command line (dotnet test) then reopened my project in VS2017. During the launch I got a "Inconsistent Line Endings" prompt for my test .cs file. I confirmed to make all line endings CR LF. Now things work!

bryanrcarlson avatar Mar 27 '17 23:03 bryanrcarlson

In my case, this is probably related to: https://github.com/dotnet/sdk/issues/1018

As stated in https://github.com/dotnet/sdk/issues/1018#issuecomment-289134060 the following comment and discussion https://github.com/Microsoft/msbuild/issues/1603#issuecomment-283104367 gives a possible solution.

fredrikhr avatar Mar 29 '17 14:03 fredrikhr

I had the same problem. Using the solution outlined by bryanrcarlson solved the issue. Thanks!

andrey-yemelyanov avatar Apr 12 '17 13:04 andrey-yemelyanov

I had the same problem. Using the solution outlined by @bryanrcarlson solved the issue. Thanks! sorry @andrey-yemelyanov , I copied your comment.

italojs avatar May 10 '17 17:05 italojs

I had the same problem with xUnit and solved this problem changing project type from Library to Console Application:

<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netcoreapp1.1|AnyCPU'">
  <OutputType>exe</OutputType>
</PropertyGroup>

<PropertyGroup>
  <TargetFrameworks>netcoreapp1.1;net461</TargetFrameworks>
  <AssemblyName>MyProject.UnitTests</AssemblyName>
  <ApplicationIcon />
  <OutputTypeEx>exe</OutputTypeEx>
  <StartupObject />
</PropertyGroup>

My final csproj: https://gist.github.com/ircnelson/9cbddb681d520d7f581dbfc99709a9e1

ircnelson avatar May 23 '17 13:05 ircnelson

I also had the same problem. Using VS 2017 with .Net Core 1.1.1, Microsoft.NET.Test.Sdk(15.0.0), xunit(2.2.0), xunit.runner.visualstudio(2.2.0).

The solution by @bryanrcarlson solved the issue. Thanks! I did also copy the comment from @andrey-yemelyanov, Thanks!

ospersson avatar May 31 '17 14:05 ospersson

I am having the exact same problem. @bryanrcarlson's solution does not help. There is a launchsettings.json in the target assembly, but not in the unit test assembly.

dkent600 avatar Jun 07 '17 00:06 dkent600

The solution by @ircnelson worked for me.

daninden avatar Jun 09 '17 08:06 daninden

I had the same problem. No launchsettings.json. Using the solution outlined by @bryanrcarlson solved the issue. Thanks!

malaikuangren avatar Jul 12 '17 07:07 malaikuangren

Similar issue being hit for Nunit here

jayaranigarg avatar Jul 18 '17 13:07 jayaranigarg

I hit this error while debugging an MSTest test case in VS 2017 (version 15.3.5)

The solution from @bryanrcarlson worked (albeit VS did not prompt about line endings on load, so I manually saved the file and selected CR LF line endings; see https://stackoverflow.com/questions/43323941/inconsistent-line-endings-visual-studio-community-2017)

danielgreen avatar Sep 20 '17 11:09 danielgreen

I cannot repro this on 15.4. I tried the project from here. Can anyone confirm please?

AbhitejJohn avatar Oct 13 '17 10:10 AbhitejJohn

Just had this problem with 15.4.1. Solved by deleting launchsettings.json that someone had added to a library project.

RehanSaeed avatar Oct 24 '17 08:10 RehanSaeed

I keep getting this every day, I end up having to clear everything down including temp directory then it lets me get back to work. I'm on VS 15.4.1

Jetski5822 avatar Oct 25 '17 07:10 Jetski5822