rnwood / smtp4dev

smtp4dev - the fake smtp email server for development and testing
BSD 3-Clause "New" or "Revised" License
3.1k stars 346 forks source link

System.ObjectDisposedException when using IMAP #1126

Closed Sajito closed 2 years ago

Sajito commented 2 years ago

When accessing the messages through IMAP, the actions won't be saved. Instead the log fills with errors about already disposed context.

Error trying to mark as read:

System.ObjectDisposedException: Cannot access a disposed context instance. A common cause of this error is disposing a context instance that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling 'Dispose' on the context instance, or wrapping it in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances.
Object name: 'Smtp4devDbContext'.
   at Microsoft.EntityFrameworkCore.DbContext.CheckDisposed()
   at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies()
   at Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Internal.IDbContextDependencies.get_EntityFinderFactory()
   at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.get_Finder()
   at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.FindAsync(Object[] keyValues)
   at Rnwood.Smtp4dev.Data.MessagesRepository.<>c__DisplayClass6_0.<MarkMessageRead>b__0() in /app/Rnwood.Smtp4dev/Data/MessagesRepository.cs:line 30
   at Rnwood.Smtp4dev.Server.TaskQueue.<>c__DisplayClass2_0.<QueueTask>b__0() in /app/Rnwood.Smtp4dev/Server/TaskQueue.cs:line 28

Error trying to delete:

System.ObjectDisposedException: Cannot access a disposed context instance. A common cause of this error is disposing a context instance that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling 'Dispose' on the context instance, or wrapping it in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances.
Object name: 'Smtp4devDbContext'.
   at Microsoft.EntityFrameworkCore.DbContext.CheckDisposed()
   at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies()
   at Microsoft.EntityFrameworkCore.DbContext.get_Model()
   at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.get_EntityType()
   at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.CheckState()
   at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.get_EntityQueryable()
   at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.System.Linq.IQueryable.get_Provider()
   at System.Linq.Queryable.Where[TSource](IQueryable`1 source, Expression`1 predicate)
   at Rnwood.Smtp4dev.Data.MessagesRepository.<>c__DisplayClass8_0.<DeleteMessage>b__0() in /app/Rnwood.Smtp4dev/Data/MessagesRepository.cs:line 47
   at Rnwood.Smtp4dev.Server.TaskQueue.<>c__DisplayClass2_0.<QueueTask>b__0() in /app/Rnwood.Smtp4dev/Server/TaskQueue.cs:line 28

Not sure if relevant, but I'm using Thunderbird 102 as IMAP client.

brad-agencyroot commented 2 years ago

Ran into a very similar issue when attempting to add flags to messages. We ended up rolling back to version 3.1.3.2 which is working fine for our needs.