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

Exceptions not captured since updating to 3.4.0 or above #1050

Closed
Camble opened this issue Jun 8, 2021 · 13 comments · Fixed by #1064
Closed

Exceptions not captured since updating to 3.4.0 or above #1050

Camble opened this issue Jun 8, 2021 · 13 comments · Fixed by #1064

Comments

@Camble
Copy link

Camble commented Jun 8, 2021

Environment

How do you use Sentry?
Sentry SaaS

Which SDK and version?
Sentry.AspNetCore 3.4.0 & 3.5.0

Steps to Reproduce

Installed & configured Sentry SDK 3.5.0 on a new ASP.NET Core 3.1 Web API.
Using webBuilder.UseSentry() in Program.cs
Configuration in appsettings.json, but also tried hardcoding values.

Expected Result

Test exception to be captured

Actual Result

No exceptions captured.
Rolled back to known working version (3.3.4) and this resolved the issue.

@Tyrrrz
Copy link
Contributor

Tyrrrz commented Jun 9, 2021

Hi! Where was the exception thrown? Inside an endpoint or somewhere else?

@bruno-garcia bruno-garcia added ASP.NET Core Bug Something isn't working labels Jun 9, 2021
@bruno-garcia bruno-garcia added this to Backlog in Mobile Platform Team Archived via automation Jun 9, 2021
@bruno-garcia
Copy link
Member

bruno-garcia commented Jun 9, 2021

@Camble Running the sample in the repo works fine:
image

Could you please share a repro so we can investigate? If you set the SDK in Debug mode, anything shows on the log to indicate the problem? Is this .NET Core 2.1, 3.1, 5.0? Or else?

@Camble
Copy link
Author

Camble commented Jun 12, 2021

@Tyrrrz Inside an endpoint, but I tried capturing a test message from various places using the SentrySdk static class.

@bruno-garcia I'm unable to share the exact repo, but I can try to reproduce in a new project. I'll investigate further. Thanks.

@bruno-garcia
Copy link
Member

Thanks @Camble . With a repro in hand we can debug it to find out what's going on. But the tests we did with our samples, we couldn't reproduce it.

@jouni-kantola
Copy link

jouni-kantola commented Jun 15, 2021

Same problem here; here's a repro:
SentryUnhandledExceptionsNotCapturedRepro.zip

The unhandled exception is not captured when the following project config is used:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Sentry.AspNetCore" Version="3.5.0" />
  </ItemGroup>
</Project>

The unhandled exception is captured with either of these combos:

  • Sentry.AspNetCore@3.3.4 works with netcoreapp3.1
  • Sentry.AspNetCore@3.5.0 works with net5.0

@Tyrrrz
Copy link
Contributor

Tyrrrz commented Jun 16, 2021

Thanks for the repro!

I debugged the issue and it looks like Sentry is crashing in DoSendEvent(...) here:

foreach (var processor in scope.GetAllExceptionProcessors())
{
processor.Process(@event.Exception, @event);
}

With this exception:

System.IO.FileLoadException: Could not load file or assembly 'System.Reflection.Metadata, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)
File name: 'System.Reflection.Metadata, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at System.Diagnostics.Internal.PortablePdbReader..ctor()
   at System.Diagnostics.EnhancedStackTrace.GetFrames(StackTrace stackTrace) in /_/modules/Ben.Demystifier/src/Ben.Demystifier/EnhancedStackTrace.Frames.cs:line 74
   at Sentry.Extensibility.SentryStackTraceFactory.CreateFrames(StackTrace stackTrace, Boolean isCurrentStackTrace)+MoveNext() in /_/src/Sentry/Extensibility/SentryStackTraceFactory.cs:line 84
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source, Int32& length)
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ReverseIterator`1.MoveNext()
   at Sentry.Extensibility.SentryStackTraceFactory.Create(StackTrace stackTrace, Boolean isCurrentStackTrace) in /_/src/Sentry/Extensibility/SentryStackTraceFactory.cs:line 67
   at Sentry.Extensibility.SentryStackTraceFactory.Create(Exception exception) in /_/src/Sentry/Extensibility/SentryStackTraceFactory.cs:line 40
   at Sentry.Internal.MainExceptionProcessor.CreateSentryException(Exception exception)+MoveNext() in /_/src/Sentry/Internal/MainExceptionProcessor.cs:line 122
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Sentry.Internal.MainExceptionProcessor.Process(Exception exception, SentryEvent sentryEvent) in /_/src/Sentry/Internal/MainExceptionProcessor.cs:line 29
   at Sentry.SentryClient.DoSendEvent(SentryEvent event, Scope scope) in /_/src/Sentry/SentryClient.cs:line 209
   at Sentry.SentryClient.CaptureEvent(SentryEvent event, Scope scope) in /_/src/Sentry/SentryClient.cs:line 77

Judging by the stacktrace, it looks like Ben.Demystifier is using System.Reflection.Metadata, Version=5.0.0.0 which is not declared as a reference in our package. Because it's present on .NET5, it works there, but not on .NET3.1 or earlier.

Edit: we DO have this package as a dependency, but only on .NET Standard 2.0, not .NET Core 3.1 target:

image

I don't see anything related in our changelog between 3.3.4 and 3.5.0 so it's probably just a submodule bump that caused this? cc @bruno-garcia

@Tyrrrz
Copy link
Contributor

Tyrrrz commented Jun 17, 2021

@bruno-garcia
Copy link
Member

bruno-garcia commented Jun 17, 2021

We haven't changed the submodule since the time we added, 5 months ago: https://github.com/getsentry/sentry-dotnet/commits/main/modules so unchanged since SDK version 3.0.0.

I wonder how does it compile if the type is not present on .NET Core 3.x? Seems odd.

Here's the diff between 3.3.4 and 3.4.0 (first version you can reproduce the error):
3.3.4...3.4.0

@Tyrrrz Isn't the problem is the version though? The one in the runtime will be 3.x.x and we're depending on 5.0.0.

Ben.Demystifier depends on 5.0.0 so that explains the problem.

We don't rely on the csproj since we just bring in the .cs files and compile them with our SDK. So really I still don't know how this happens (and why it doesn't in CI when we run tests on .NET Core 3.1)

I'm not sure how tests pass though.

Workaround

Add a dependency: <PackageReference Include="System.Reflection.Metadata" Version="5.0.0" /> to your app directly

@bruno-garcia
Copy link
Member

bruno-garcia commented Jun 18, 2021

We've added it as a dependency explicitly to work around this issue. It's available on our latest preview: https://github.com/getsentry/sentry-dotnet/releases/tag/3.6.0-alpha.2

Again, workaround for you without the need to upgrade the Sentry SDK:

Add a dependency: <PackageReference Include="System.Reflection.Metadata" Version="5.0.0" /> to your app directly

@bruno-garcia
Copy link
Member

Version 3.6.0 was already released with this fix: https://www.nuget.org/packages/Sentry/3.6.0

@bruno-garcia bruno-garcia added this to Parked in v3.x Jul 12, 2021
@bruno-garcia bruno-garcia moved this from Parked to Done in v3.x Jul 12, 2021
@SirSalamandra
Copy link

Hey guys, I was looking the new version of Sentry.AspNetCore and looks like the dependency for System.Reflection.Metadata is not present on .NET Core 3.x again.

I tried the workaround and it worked, so maybe it was unintended removed?

Link for the new version: https://www.nuget.org/packages/Sentry/3.30.0#dependencies-body-tab

@mattjohnsonpint
Copy link
Contributor

@SirSalamandra - Thanks. I'll take a look asap.

@mattjohnsonpint
Copy link
Contributor

Restored in #2302. Adding the dependency manually to your project should be fine in the meantime. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ASP.NET Core Bug Something isn't working
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

6 participants