Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugging XUnit test cases fails critically #558

Closed
srivatsn opened this issue Mar 1, 2017 · 32 comments
Closed

Debugging XUnit test cases fails critically #558

srivatsn opened this issue Mar 1, 2017 · 32 comments

Comments

@srivatsn
Copy link

srivatsn commented Mar 1, 2017

From @couven92 on February 24, 2017 10:45

Ref.: microsoft/VSProjectSystem#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/project-system#1620

@srivatsn
Copy link
Author

srivatsn commented Mar 1, 2017

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

@codito
Copy link
Contributor

codito commented Mar 2, 2017

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.

@fredrikhr
Copy link

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.

@flagbug
Copy link

flagbug commented Mar 21, 2017

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

@fredrikhr
Copy link

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...

@cobyzeng
Copy link

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

@bryanrcarlson
Copy link

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!

@fredrikhr
Copy link

In my case, this is probably related to: dotnet/sdk#1018

As stated in dotnet/sdk#1018 (comment) the following comment and discussion dotnet/msbuild#1603 (comment) gives a possible solution.

@andrey-yemelyanov
Copy link

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

@italojs
Copy link

italojs commented May 10, 2017

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

@ircnelson
Copy link

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

@ospersson
Copy link

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!

@dkent600
Copy link

dkent600 commented Jun 7, 2017

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.

@daninden
Copy link

daninden commented Jun 9, 2017

The solution by @ircnelson worked for me.

@malaikuangren
Copy link

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

@jayaranigarg
Copy link
Member

Similar issue being hit for Nunit here

@danielgreen
Copy link

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)

@AbhitejJohn
Copy link
Contributor

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

@RehanSaeed
Copy link

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

@Jetski5822
Copy link

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

@AbhitejJohn
Copy link
Contributor

Thanks for the responses.
@Jetski5822 : Do you happen to have repro steps/a project that you could share? That would greatly help.

@snkota
Copy link

snkota commented Nov 7, 2017

@riQQ
Copy link
Contributor

riQQ commented Dec 20, 2017

@AbhitejJohn Clean solution worked for me
Edit: Rereading your comment, you are looking for a reproduction and not a workaround. Sadly, i can't reproduce the issue.

@bigmealy
Copy link

I'm having this problem with VS 15.5.4
If I load solution on startup, then ask to "debug" a unit test, I get the fatal error message.
If load solution on startup, open the "Manage NuGet Packages for Solution" window, then ask to "debug" a unit test, it works! Stumbled upon this workaround for me accidentally...still can't fathom why

@HristoHentov
Copy link

Had the same isssue with VS 2017 15.5.6 and .NET Core 2.0 using XUnit.

Had no launchsettings.json, and the solution by @bryanrcarlson did not help.
Managed to fix it by disabling the nUnit test adpators from Tools->Extensions and Updates

@trevorchunestudy
Copy link

No dice on @bryanrcarlson and no launchsettings.json. Fixed by updating .netcore packages to latest (2.0.5). Debug tests now working. ???

@svickers
Copy link

svickers commented Mar 1, 2018

I've run in to the same problem and none of the fixes listed here helped. I started a brand new asp.net core web app and hit the same roadblock of not being able to debug tests. The tests are embedded in the main project file and that appears to be causing the problem. If I create a regular unit test project in the same solution then debugging is fine. Here is a repo repo: https://github.com/svickers/Debug_no_worky

@fractionalJoe
Copy link

Clean Solution worked for me as well.

@scottsauber
Copy link

Add one more for deleting launchsettings.json fixed it. If someone is unsure where it is, it's under the Properties folder.

@ognjenkurtic
Copy link

Still failing with Visual Studio 15.8.6 and xunit 2.4.0. Tried all of the above workarounds to no avail. Running of tests works but debugging fails with
image

@CalArabshahi
Copy link

Failing with VS 15.9.5, NUnit3TestAdapter 3.12, Microsoft.NET.Test.Sdk 15.9 when debugging tests targeting .NET Framework 4.52 . But it works when debugging the same test targeting .NET Core App 2.0/2.2.

@AbhitejJohn
Copy link
Contributor

@CalArabshahi, @ognjenkurtic : If you haven't already, could you delete the .vs folder for your solution and try this out please(@ognjenkurtic you might want to update to the latest as well)? If that doesn't work, would you be able to file an issue in developercommunity and paste a link here please? This specific issue would get more traction there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests