Open Closed

Got 'Instances cannot be resolved...' when call SeedDataAsync in distributed event handler #253


User avatar
0
rachanee-mwp created

Check the docs before asking a question: https://docs.abp.io/en/commercial/latest/ Check the samples, to see the basic tasks: https://docs.abp.io/en/commercial/latest/samples/index The exact solution to your question may have been answered before, please use the search on the homepage.

  • ABP Framework version: v2.9.0
  • UI type: Angular
  • Tiered (MVC) or Identity Server Seperated (Angular): Identity Server Seperated
  • Exception message and stack trace:
System.ObjectDisposedException
  HResult=0x80131622
  Message=Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it has already been disposed.
  Source=Autofac
  StackTrace:
   at Autofac.Core.Lifetime.LifetimeScope.CheckNotDisposed()
   at Autofac.Core.Lifetime.LifetimeScope.BeginLifetimeScope(Object tag)
   at Autofac.Core.Lifetime.LifetimeScope.BeginLifetimeScope()
   at Autofac.Extensions.DependencyInjection.AutofacServiceScopeFactory.CreateScope()
   at Volo.Abp.AspNetCore.DependencyInjection.HttpContextServiceScopeFactory.CreateScope()
   at Volo.Abp.Data.DataSeeder.<SeedAsync>d__7.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
   at Castle.DynamicProxy.AsyncInterceptorBase.<ProceedAsynchronous>d__13.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
   at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapter.<ProceedAsync>d__7.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
   at Volo.Abp.Uow.UnitOfWorkInterceptor.<InterceptAsync>d__3.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
   at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.&lt;InterceptAsync&gt;d__2.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Mwp.Data.MwpDbMigrationService.&lt;SeedDataAsync&gt;d__13.MoveNext() in D:\Git\Mwp\aspnet-core\src\Mwp.Domain\Data\MwpDbMigrationService.cs:line 100
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Mwp.Data.MwpDbMigrationService.&lt;InitiliaseTenantDatabaseAsync&gt;d__15.MoveNext() in D:\Git\Mwp\aspnet-core\src\Mwp.Domain\Data\MwpDbMigrationService.cs:line 124
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Mwp.Tenant.TenantResourceManager.&lt;InitialiseTenantDatabase&gt;d__11.MoveNext() in D:\Git\Mwp\aspnet-core\src\Mwp.Domain\Tenant\TenantResourceManager.cs:line 97
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
   at Castle.DynamicProxy.AsyncInterceptorBase.&lt;ProceedAsynchronous&gt;d__13.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
   at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapter.&lt;ProceedAsync&gt;d__7.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
   at Volo.Abp.Uow.UnitOfWorkInterceptor.&lt;InterceptAsync&gt;d__3.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
   at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.<InterceptAsync>d__2.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Mwp.Tenant.Events.Result.DatabaseProvisionResultEventHandler.<ProcessSuccessProvisioning>d__5.MoveNext() in D:\Git\Mwp\aspnet-core\src\Mwp.Domain\Tenant\Events\Result\DatabaseProvisionResultEventHandler.cs:line 52
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__139_1(Object state)
   at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
  • Steps to reproduce the issue: Call SeedDataAsync(tenant) from a distiributed event hanlder.

Actually, calling MigrateDatabaseSchemaAsync(tenant) produced this same error as well but I tried wrapping migrator statements inside ServiceScope and its solved the error. I have no idea how to do on SeedDataAync(tenant) however.


6 Answer(s)
  • User Avatar
    0
    alper created
    Support Team Director

    are you returning an Entity to the presentation layer? or is it throwing the ex in MigrateAsync()

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Are you using rabbitmq or default distributed event bus provider?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi

    I use default and rabbitmq distributed event bus provider, can't reproduce your problem.

    Can your provide steps to reproduce? Thanks.

  • User Avatar
    0
    rachanee-mwp created

    @alper No I'm not trying to return entity to presentation layer, these codes are inside event handler to migrate database after provisioned resources dinamically.

    @liangshiwei I use RabbitMq. Sorry that you cannot reproduced the error.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Can you share more code and steps to reproduce? Thanks.

  • User Avatar
    0
    rachanee-mwp created

    @liangshiwei and @alper,

    Sorry, It was my fault that I call method InitiliaseTenantDatabaseAsync(tenant) inside a non-awaitable method. That make the LifttimeScope end before all statements finish and throw the error.

    I just change the method to be awaitable and the error gone.

    Thank you for your promptly support, however.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.3.0-preview. Updated on April 16, 2025, 12:13