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

StackTrace/StackFrame don't have a file name or position in .NET Core on Windows, but do with .NET Core on Unix and .NET Framework #22302

Closed
hughbe opened this issue Jun 15, 2017 · 21 comments · Fixed by dotnet/corefx#21521
Assignees
Labels
area-System.Diagnostics bug tenet-compatibility Incompatibility with previous versions or .NET Framework
Milestone

Comments

@hughbe
Copy link
Contributor

hughbe commented Jun 15, 2017

The following example is a test that passes with netfx, passes with netcoreapp on Unix, but not with netcoreapp on Windows.

[Fact]
public void Ctor_FileInfo_CorrectlyGetsFileName()
{
    var stackTrace = new StackTrace(fNeedFileInfo: true);
    StackFrame[] frames = stackTrace.GetFrames());
    Assert.True(frames.Any(f => f.GetFileName() != null));
}
@karelz
Copy link
Member

karelz commented Jun 15, 2017

That's weird. @joperezr is it on purpose?

@hughbe
Copy link
Contributor Author

hughbe commented Jun 15, 2017

This seems like a recent regression. I actually noticed it before writing tests in dotnet/corefx#21040 (they fail on Unix because of this bug), because the stack trace test failures no longer have line numbers or file info in them with .NET Core. This made it super hard to track down failures. But when I changed to .NET Framework, I had line numbers

I thought it was just a tooling thing, but looks like a bug, and a pretty bad one at that.

@karelz
Copy link
Member

karelz commented Jun 15, 2017

That looks suspicious, @joperezr can you please take a look for 2.0 into it? (or route it ASAP) Thanks!
cc @danmosemsft

@danmoseley
Copy link
Member

@noahfalk ?

@hughbe
Copy link
Contributor Author

hughbe commented Jun 15, 2017

This issue gets even weirder. I only occurs in Debug mode on Windows, not Release

@stephentoub
Copy link
Member

cc: @mikem8361

@mikem8361 mikem8361 self-assigned this Jun 15, 2017
@mikem8361
Copy link
Member

If the only scenario that this occurs is on Windows Debug, then I'm moving it to 2.1.

@hughbe
Copy link
Contributor Author

hughbe commented Jun 16, 2017

@mikem8361 could you also confirm that this isn't the cause of the following difference between netfx and netcoreapp (on Windows)

Code:

[Fact]
public void InvokeMethodThatThrowsException()
{
    ThrowExceptionPlease();
}

public void ThrowExceptionPlease()
{
    throw new Exception();
}

Netfx:

System.Diagnostics.Tests.StackTraceTests.InvokeMethodThatThrowsException [FAIL]
        System.Exception : Exception of type 'System.Exception' was thrown.
        Stack Trace:
          C:\Users\hugh\Documents\GitHub\corefx\src\System.Diagnostics.StackTrace\tests\StackTraceTests.cs(274,0): at S
  ystem.Diagnostics.Tests.StackTraceTests.ThrowExceptionPlease()
          C:\Users\hugh\Documents\GitHub\corefx\src\System.Diagnostics.StackTrace\tests\StackTraceTests.cs(269,0): at S
  ystem.Diagnostics.Tests.StackTraceTests.InvokeMethodThatThrowsException()

Netcoreapp:

System.Diagnostics.Tests.StackTraceTests.InvokeMethodThatThrowsException [FAIL]
        System.Exception : Exception of type 'System.Exception' was thrown.
        Stack Trace:
              at System.Diagnostics.Tests.StackTraceTests.ThrowExceptionPlease()

I can also repro this example above in Release mode, so I'm not sure if it's related, as the tests seemed to fail in Windows Release in the dotnet/corefx#21040.

Note that netcoreapp has no line numbers and no no file name so this makes things hard to action on. I thought it was just a tooling thing but what do I know

@mikem8361
Copy link
Member

What version of the .NET Core Windows runtime were you using? Did you generate portable PDBs or Windows PDBs for your test app? If you are using Windows PDBs, make sure that microsoft.diasymreader.native.amd64.dll is in your shared framework binaries ("\Program Files\dotnet\shared\Microsoft.NETCore.App<version>"). If your app is built with Portable PDBs, there was a bug in System.Diagnostics.StackTrace that should be fixed now.

@hughbe
Copy link
Contributor Author

hughbe commented Jun 21, 2017

I'm running from master in the test projects for master

@hughbe
Copy link
Contributor Author

hughbe commented Jun 21, 2017

(As in, these are contributions to corefx, not my own app)
You may want to take a look at dotnet/corefx#21040

@hughbe
Copy link
Contributor Author

hughbe commented Jun 23, 2017

Sorry to keep flogging a dead horse, but I'm not sure why the following has different behaviour in .NET Core vs .NET Framework.

  • Clone corefx and run build and build -framework=netfx
  • Navigate to src/System.Composition/tests and add the following test to ExportTests.cs
[Fact]
public void THROW()
{
    throw new InvalidOperationException();
}
  • Run msbuild /T:BuildAndTest and observe the following
Discovering: System.Composition.Runtime.Tests
  Discovered:  System.Composition.Runtime.Tests
  Starting:    System.Composition.Runtime.Tests
     System.Compostition.Tests.ExportTests.THROW [FAIL]
        System.InvalidOperationException : Operation is not valid due to the current state of the object.
        Stack Trace:
              at System.Compostition.Tests.ExportTests.THROW()
  Finished:    System.Composition.Runtime.Tests
  • Run msbuild /T:BuildAndTest /P:TargetGroup=netfx and observe the following
Discovering: System.Composition.Runtime.Tests
    Discovered:  System.Composition.Runtime.Tests
    Starting:    System.Composition.Runtime.Tests
      System.Compostition.Tests.ExportTests.THROW [FAIL]
        System.InvalidOperationException : Operation is not valid due to the current state of the object.
        Stack Trace:
          C:\Users\hugh\Documents\GitHub\corefx\src\System.Composition.Runtime\tests\ExportTests.cs(15,0): at System.Co
  mpostition.Tests.ExportTests.THROW()
    Finished:    System.Composition.Runtime.Tests

Notice that there are no line numbers or file paths for netcoreapp. If this is a bug in netcoreapp or even in the tooling for corefx, then isn't this really bad? In more advanced examples than the one I added, we can't diagnose where a test failure happened!

@mikem8361
Copy link
Member

The source/line number info on .NET Core is missing because microsoft.diasymreader.native.amd64.dll doesn't exist in the bin directory. It is from the Microsoft.DiaSymReader.Native package which is part of the shared framework, but doesn't seem to be part of the corefx runtime binaries. It is used by the coreclr runtime to load Windows PDBs. Now if the tests used portable PDBs that would work on (.NET Core only).

@mikem8361
Copy link
Member

And that is also reason there are source/line numbers on the Linux runs (because they can only use portable PDBs).

@danmoseley
Copy link
Member

danmoseley commented Jun 24, 2017

microsoft.diasymreader.native.amd64.dll doesn't exist in the bin directory. It is from the Microsoft.DiaSymReader.Native package which is part of the shared framework, but doesn't seem to be part of the corefx runtime binaries

@weshaggard can we fix this? (or change to portable pdb's on windows)

@danmoseley
Copy link
Member

If I manually copy "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Roslyn\*diasym*" to
eg C:\git\corefx\bin\Windows_NT.AnyCPU.Debug\System.Console.Tests\netstandard I get line numbers in my UAP tests!

@weshaggard what is the correct way of fixing this? for now I'm pasting this line into tests.targets, which only works for uap. <TestCommandLines Include='copy /y "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Roslyn\*diasym*" .'/>

@mellinoe
Copy link
Contributor

The right way to fix it is to reference the Microsoft.DiaSymReader.Native package in this project: https://github.com/dotnet/corefx/blob/master/external/test-runtime/XUnit.Runtime.depproj. The build system should do the rest of the work to deploy it to the test runtime folder, and things should work from there (at least based on my understanding of the discussion above).

@danmoseley
Copy link
Member

Let's leave this open while we see whether it fixes the problem.

@weshaggard
Copy link
Member

Yes what @mellinoe says is the correct way to fix this.

@mikem8361
Copy link
Member

Fixed with PR dotnet/coreclr#14696

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 2.1.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Diagnostics bug tenet-compatibility Incompatibility with previous versions or .NET Framework
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants