smtp4dev icon indicating copy to clipboard operation
smtp4dev copied to clipboard

System.ObjectDisposedException when using IMAP

Open Sajito opened this issue 2 years ago • 1 comments

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.

Sajito avatar Jul 07 '22 05:07 Sajito

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.

brad-agencyroot avatar Jul 28 '22 20:07 brad-agencyroot