Run task: An entity object cannot be referenced by multiple instances of IEntityChangeTracker.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 years ago
Hi guys,

Clean version of NopCommerce (from CodePlex, commit 21c5ed4b8bd2).
Go to  Administration -> Schedule tasks -> "Run now" for "Delete guests" task.
You will get an error:
An entity object cannot be referenced by multiple instances of IEntityChangeTracker.

Link to screenshot: http://screencast.com/t/UWHJXY65bS2

Stack Trace:

[InvalidOperationException: An entity object cannot be referenced by multiple instances of IEntityChangeTracker.]
   System.Data.Entity.Core.Objects.ObjectContext.VerifyContextForAddOrAttach(IEntityWrapper wrappedEntity) +178
   System.Data.Entity.Core.Objects.ObjectContext.AddSingleObject(EntitySet entitySet, IEntityWrapper wrappedEntity, String argumentName) +107
   System.Data.Entity.Core.Objects.DataClasses.EntityReference.AddEntityToObjectStateManager(IEntityWrapper wrappedEntity, Boolean doAttach) +67
   System.Data.Entity.Core.Objects.DataClasses.RelatedEnd.AddGraphToObjectStateManager(IEntityWrapper wrappedEntity, Boolean relationshipAlreadyExists, Boolean addRelationshipAsUnchanged, Boolean doAttach) +58
   System.Data.Entity.Core.Objects.DataClasses.RelatedEnd.IncludeEntity(IEntityWrapper wrappedEntity, Boolean addRelationshipAsUnchanged, Boolean doAttach) +289
   System.Data.Entity.Core.Objects.DataClasses.EntityReference`1.Include(Boolean addRelationshipAsUnchanged, Boolean doAttach) +234
   System.Data.Entity.Core.Objects.DataClasses.RelationshipManager.AddRelatedEntitiesToObjectStateManager(Boolean doAttach) +229
   System.Data.Entity.Core.Objects.ObjectContext.AddObject(String entitySetName, Object entity) +810
   System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName) +202
   System.Data.Entity.Internal.Linq.InternalSet`1.Add(Object entity) +165
   System.Data.Entity.DbSet`1.Add(TEntity entity) +70
   Nop.Data.EfRepository`1.Insert(T entity) +211
   Nop.Services.Logging.DefaultLogger.InsertLog(LogLevel logLevel, String shortMessage, String fullMessage, Customer customer) +268
   Nop.Services.Logging.LoggingExtensions.Error(ILogger logger, String message, Exception exception, Customer customer) +25
   Nop.Admin.Controllers.BaseAdminController.OnException(ExceptionContext filterContext) +149
   System.Web.Mvc.ControllerActionInvoker.InvokeExceptionFilters(ControllerContext controllerContext, IList`1 filters, Exception exception) +169
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +203
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +19
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +51
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288
9 years ago
Hi Vitaly,

thanks a lot for reporting. Currently investigating it - https://nopcommerce.codeplex.com/workitem/12188
9 years ago
Fixed. Please have a look at changeset d73163efd9af
9 years ago
Thank you!
8 years ago
Andrei,

If I want to run async operation in ITask.Execute using Task.Run I need new its own ILifetimeScope instance because scope for HttpContext will be disposed earlier than async operation is completed.

Regards.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.