Failure to capture event: System.ObjectDisposedException: Cannot access a disposed object.
See original GitHub issueHi 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:
- Created 5 years ago
- Comments:36 (14 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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!
@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
toSentrySdk
in 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
.