question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failure to capture event: System.ObjectDisposedException: Cannot access a disposed object.

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:36 (14 by maintainers)

github_iconTop GitHub Comments

3reactions
bruno-garciacommented, Jan 8, 2019

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 Hub it 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!

2reactions
bruno-garciacommented, Nov 6, 2018

@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 Hub to SentrySdk in the SentryMiddleware. 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 to SentrySdk.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot access a disposed object. A common cause of this ...
A common cause of this error is disposing a context that was resolved from dependency injection and then later trying to use the...
Read more >
Cannot access a disposed context instance in var result = ...
Hello! I am writing a Login Form for a site on the MVC Net Core 6 Web App, but I can't find out...
Read more >
System.ObjectDisposedException: Cannot access a ...
Since none of the panel control we are using get deliberately disposed, this error makes no real sense, Our application is too big...
Read more >
C# Event Handlers triggering Unhandled Exception ...
System.ObjectDisposedException: Cannot access a disposed object. For some reason, it looks like the event wired up in the disposed object's ...
Read more >
Cannot access a disposed object
Hi In our catch up subscriptions we are getting a CatchUpError + “System.ObjectDisposedException: Cannot access a disposed object” from the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found