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

AssertFailedException reveals internal stack trace in .NET 7.0 #1540

Closed
gao-artur opened this issue Jan 6, 2023 · 3 comments
Closed

AssertFailedException reveals internal stack trace in .NET 7.0 #1540

gao-artur opened this issue Jan 6, 2023 · 3 comments

Comments

@gao-artur
Copy link

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

  <PropertyGroup>
    <TargetFrameworks>net6.0;net7.0</TargetFrameworks>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
    <PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
    <PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
  </ItemGroup>

</Project>
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TestProject1;

[TestClass]
public class TestClass1
{
    [TestMethod]
    public void Test()
    {
        Assert.Fail();
    }
}

dotnet test result

Microsoft (R) Test Execution Command Line Tool Version 17.4.0 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
  Failed Test [17 ms]
  Error Message:
   Assert.Fail failed.
  Stack Trace:
     at TestProject1.TestClass1.Test() in C:\github\junk\TestProject2\TestProject1\UnitTest1.cs:line 11


Failed!  - Failed:     1, Passed:     0, Skipped:     0, Total:     1, Duration: 30 ms - TestProject1.dll (net6.0)
Test run for C:\github\junk\TestProject2\TestProject1\bin\Debug\net7.0\TestProject1.dll (.NETCoreApp,Version=v7.0)
Microsoft (R) Test Execution Command Line Tool Version 17.4.0 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
  Failed Test [16 ms]
  Error Message:
   Assert.Fail failed.
  Stack Trace:
     at TestProject1.TestClass1.Test() in C:\github\junk\TestProject2\TestProject1\UnitTest1.cs:line 11
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)

Please note the following stack trace under .NET 7.0, which doesn't exist in .NET 6.0

   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)

dotnet --list-sdks result

6.0.404 [C:\Program Files\dotnet\sdk]
7.0.101 [C:\Program Files\dotnet\sdk]
@ghost ghost added the Needs: Triage 🔍 label Jan 6, 2023
@Evangelink
Copy link
Member

Hi @gao-artur,

Thanks for reporting this issue. I can confirm I can replicate the issue in VS and in CLI.

We will investigate it shortly and report back findings.

@Evangelink
Copy link
Member

It seems to be a bug of runtime that's postponed for .NET 8 (see dotnet/runtime#68923). I will see if we can do some kind of hack ourselves in the meantime for .NET 7.

@Evangelink
Copy link
Member

I had a quick look and it seems to dangerous/unstable to introduce hack in MSTest to remove part of stack trace depending on runtime version. I will move forward by closing this issue.

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

2 participants