-
Notifications
You must be signed in to change notification settings - Fork 29
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
Cannot access a disposed object. Object name: 'IServiceProvider'. #204
Comments
hmm I seem to also be able to get "SaveChangesWithoutTriggersAsync(), but it throws this exception 'System.InvalidOperationException: 'A triggerSession has already been created''!" occasionally too. I think there's definitely some threadsafety or leakage issues happening for some reason. |
wonder if it's due to TriggerSessionSaveChangesInterceptor being registered against the db factory like I did, that might effectively make it shared? |
yup, seems that was it! using AddInterceptors like this is bad
as it means it shares the one interceptor between all dbcontexts (threading issue). adding it in the dbcontext in onconfiguring seems to work
(still no idea why i had to add it myself, but triggers didn't fire without it) |
That said you can't use OnConfiguring if Db Pooling is enabled :( System.InvalidOperationException: 'OnConfiguring' cannot be used to modify DbContextOptions when DbContext pooling is enabled. |
Curiously I think for the Db Pooling, it might actually work better to use the v2 mode where you extend the dbcontext instead. May be a good reason not to remove it in v4? |
also recommend against using services.AddDbContext(options => options.UseTriggers(triggerOptions => triggerOptions.AddAssemblyTriggers())); syntax as it does an assembly scan each context cretaion (50ms for me). |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Occasionally hit the following which kills our app.
using latest version 3.
We've only recently implemented EFC Triggered, so we may have done something wrong - this issue is just in case you know about something, otherwise if we figure out what we did wrong we'll add to document it.
potentially related to #124?
we did add the dbcontextfactory by copying code from #195
being called in program.cs (Azure Functions, dotnet 8, isolated)
Also saw the following stackoverflow post which suggests it may be better to inject
IServiceScopeFactory
instead ofIServiceProvider
, which might make sense if there's a singleton object somewhere, but i haven't seen one.https://stackoverflow.com/questions/76745332/c-sharp-timer-cannot-access-a-disposed-object-object-name-iserviceprovider
The text was updated successfully, but these errors were encountered: