sentry-dotnet: Failure to capture event: System.ObjectDisposedException: Cannot access a disposed object.
Hi I tried sentry in my asp.net core app. When I turn on Debug mode I can see this exception:
Sentry.ISentryClient[0]
Failure to capture event: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'SentryClient'.
at Sentry.SentryClient.CaptureEvent(SentryEvent event, Scope scope) in C:\projects\sentry-dotnet\src\Sentry\SentryClient.cs:line 77
at Sentry.Internal.Hub.CaptureEvent(SentryEvent evt, Scope scope) in C:\projects\sentry-dotnet\src\Sentry\Internal\Hub.cs:line 95
dbugdbug: Sentry.ISentryClient[0]
Configuring the scope.
: Sentry.ISentryClient[0]
Configuring the scope.
dbugfail: Sentry.ISentryClient[0]
Configuring the scope.
: Sentry.ISentryClient[0]
Failure to capture event: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'SentryClient'.
at Sentry.SentryClient.CaptureEvent(SentryEvent event, Scope scope) in C:\projects\sentry-dotnet\src\Sentry\SentryClient.cs:line 77
at Sentry.Internal.Hub.CaptureEvent(SentryEvent evt, Scope scope) in C:\projects\sentry-dotnet\src\Sentry\Internal\Hub.cs:line 95
I dont think I have some special setup. Its dotnet core 2.1 web api with EF core and Autofac DI container. Unfortunately I can post here whole project but if you need more info don’t hesitate to ask.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 36 (14 by maintainers)
Commits related to this issue
- use ConfigureServices instead of UseStartup * match original issue description #103 — committed to getsentry/sentry-dotnet by bruno-garcia 6 years ago
- bug: attempt to repro ObjectDisposedException Added swagger as reported in #103 — committed to getsentry/sentry-dotnet by bruno-garcia 6 years ago
A late Christmas miracle! Took a while but finally released a package with a fix for this issue.
The SDK will no longer hold on to the last
Hubit creates via the DI container. Instead, it will use an accessor (Func<IHub>) so if your app or some framework requires building containers after the SDK is initialized, the new Hub will just take over. That is, so any integration you have enabled (say ASP.NET Core and Serilog, for example) will share state.One example: crumbs added via the Serilog integration are sent out if the ASP.NET Core integration captures an exception, or vice-versa.
The release is version
1.1.2-beta. Please give it a try and let give some feedback if there’s anything wrong.https://www.nuget.org/packages/Sentry.AspNetCore/1.1.2-beta
Thanks everyone who helped tracking the error and @alesdvorakcz for giving the repro!
@prencher as I mentioned above, we’ll need to work around this issue in the SDK itself.
The proposed work around in this thread for you is only until we ship a new version which no longer requires you to work around this issue.
One way I’m thinking we can work around it is simply bind
HubtoSentrySdkin theSentryMiddleware. In that case even if multiple containers are built, the last one to resolve the application pipeline is made sure to be the one bound toSentrySdk.I’ll try to create a reproduction sample but the repro I created is working fine. I’ll further investigate this issue by taking the Sentry source into my project and debug the client the next days.
I tried to made small repo to isolate problem but it works fine there… maybe it has some connection with other asp services I use (EF Core, …). I will try to find problem and then I will post it.
I will try to locate problem more specifically and send you small repo. Thanks