Open Closed

System.ObjectDisposedException #7361


User avatar
0
drg_tverkroost created

Hi there,

Got this exception sometimes. I can't reproduce it unfortunately. Only what I know is getting menu from MainMenuProvider.

Unhandled exception in circuit '0Ii8lf77GLluHYmZrOx5tkCI26mNfhJH2DUyX1YmOpQ'. System.ObjectDisposedException: Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it (or one of its parent scopes) has already been disposed. at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(ResolveRequest request) at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable1 parameters, Object& instance) at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable1 parameters) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at Volo.Abp.SettingManagement.Blazor.Settings.EmailingPageContributor.CheckPermissionsInternalAsync(SettingComponentCreationContext context) at Volo.Abp.SettingManagement.Blazor.Settings.EmailingPageContributor.CheckPermissionsAsync(SettingComponentCreationContext context) at Volo.Abp.SettingManagement.Blazor.Menus.SettingManagementMenuContributor.CheckAnyOfPagePermissionsGranted(SettingManagementComponentOptions settingManagementComponentOptions, SettingComponentCreationContext settingComponentCreationContext) at Volo.Abp.SettingManagement.Blazor.Menus.SettingManagementMenuContributor.ConfigureMainMenuAsync(MenuConfigurationContext context) at Volo.Abp.SettingManagement.Blazor.Menus.SettingManagementMenuContributor.ConfigureMenuAsync(MenuConfigurationContext context) at Volo.Abp.UI.Navigation.MenuManager.GetInternalAsync(String name) at Volo.Abp.UI.Navigation.MenuManager.GetAsync(String[] menuNames) at Volo.Abp.AspNetCore.Components.Web.LeptonTheme.Components.ApplicationLayout.Navigation.MainMenuProvider.GetMenuAsync() at NEXTjeugd.Blazor.Components.ApplicationLayout.MainHeader.OnInitializedAsync() in D:\a\1\s\src\NEXTjeugd.Blazor\Components\ApplicationLayout\MainHeader.razor.cs:line 30 at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync() at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState) 2024-06-18 05:13:34.802 +00:00 [WRN] Unhandled exception rendering component: Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it (or one of its parent scopes) has already been disposed.

Sample code:

How to fix that?

ABP Framework version**: v5.3.0 UI Type**: Blazor Server Database System**: EF Core (SQL Server) Tiered (for MVC) Exception message and full stack trace**:


8 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Hi there,

    Got this exception sometimes. I can't reproduce it unfortunately.

    2024-06-18 05:13:34.809 +00:00 [ERR] Unhandled exception in circuit '0Ii8lf77GLluHYmZrOx5tkCI26mNfhJH2DUyX1YmOpQ'. System.ObjectDisposedException: Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it (or one of its parent scopes) has already been disposed. at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(ResolveRequest request) at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable1 parameters, Object& instance) at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable1 parameters) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at Volo.Abp.ObjectMapping.DefaultObjectMapper.Map[TSource,TDestination](TSource source) at Volo.Abp.LanguageManagement.DatabaseLanguageProvider.bDKc3J4YN() at Volo.Abp.Caching.DistributedCache2.GetOrAddAsync(TCacheKey key, Func1 factory, Func1 optionsFactory, Nullable1 hideErrors, Boolean considerUow, CancellationToken token) at Volo.Abp.LanguageManagement.DatabaseLanguageProvider.GetLanguagesAsync() at Volo.Abp.AspNetCore.Components.Server.LeptonTheme.LeptonThemeToolbarContributor.ConfigureToolbarAsync(IToolbarConfigurationContext context) at Volo.Abp.AspNetCore.Components.Web.Theming.Toolbars.ToolbarManager.GetAsync(String name) at Volo.Abp.AspNetCore.Components.Web.LeptonTheme.Components.ApplicationLayout.MainHeader.MainHeaderToolbar.OnInitializedAsync() at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync() at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

    How to fix that?

    ABP Framework version**: v5.3.0 UI Type**: Blazor Server Database System**: EF Core (SQL Server) Tiered (for MVC) Exception message and full stack trace**:

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you share full logs.txt file?

    Thanks

    liming.ma@volosoft.com

  • User Avatar
    0
    drg_tverkroost created

    Hi

    Attached full log.txt of yesterday

    full log.txt

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you share the Logs.txt file to liming.ma@volosoft.com

    Thanks.

  • User Avatar
    0
    drg_tverkroost created

    Hi,

    According to log.txt file some other exceptions ocurred as well. I can't really explain why they occurred suddenly. A views exceptions:

    1. 2024-06-18 09:21:03.649 +00:00 [ERR] Unhandled exception in circuit 'SIhZtD4OOOkA9DL-XkSAqW_d-nKC2hSQ78CMzf6XNwE'. System.TimeoutException: Did not receive any data in the allotted time. at System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result) at System.IO.Pipelines.Pipe.GetReadAsyncResult() at System.IO.Pipelines.PipeReaderStream.ReadAsyncInternal(Memory`1 buffer, CancellationToken cancellationToken)

    2. 2024-06-18 11:45:46.597 +00:00 [ERR] An exception occurred while iterating over the results of a query for context type 'Volo.Abp.LanguageManagement.EntityFrameworkCore.LanguageManagementDbContext'. System.Threading.Tasks.TaskCanceledException: A task was canceled. at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected) at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func4 operation, Func4 verifySucceeded, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable1.AsyncEnumerator.MoveNextAsync() System.Threading.Tasks.TaskCanceledException: A task was canceled. at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected) at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func4 operation, Func4 verifySucceeded, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable1.AsyncEnumerator.MoveNextAsync()

    3. 2024-06-18 11:45:46.609 +00:00 [ERR] Connection id "0HN4FHGOAMROI", Request id "0HN4FHGOAMROI:00000002": An unhandled exception was thrown by the application.

    4. 2024-06-18 14:43:17.456 +00:00 [ERR] Unhandled exception in circuit '4NnRogiSjg5nPc_ppDUbJwo5Yyvfa4GPBshS89qJcJA'. System.InvalidOperationException: Collection was modified; enumeration operation may not execute. at Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars.PageToolbarManager.GetItemsAsync(PageToolbar toolbar) at Volo.Abp.AspNetCore.Components.Web.Theming.Layout.PageHeader.OnParametersSetAsync() at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task) at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

    Do you have any clue why they occurred?

    Kind regards, Tako Verkroost

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I need to see more logs.

    Can you share the Logs.txt file?

  • User Avatar
    0
    drg_tverkroost created

    I send all logs to you.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    System.ObjectDisposedException: Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it (or one of its parent scopes) has already been disposed.

    Can you share a project to reproduce this? liming.ma@volosoft.com

    1.

    System.TimeoutException: Did not receive any data in the allotted time.

    This is not an abp exception. I have no idea.

    2. 3.

    2024-06-18 11:45:46.597 +00:00 [ERR] An exception occurred while iterating over the results of a query for context type 'Volo.Abp.LanguageManagement.EntityFrameworkCore.LanguageManagementDbContext'. System.Threading.Tasks.TaskCanceledException: A task was canceled. 2024-06-10 09:44:29.585 +00:00 [ERR] Connection id "0HN4967LSB6F1", Request id "0HN4967LSB6F1:00000002": An unhandled exception was thrown by the application.

    System.Threading.Tasks.TaskCanceledException: A task was canceled.

    You can ignore the TaskCanceledException

    4.

    2024-06-18 14:43:17.456 +00:00 [ERR] Unhandled exception in circuit '4NnRogiSjg5nPc_ppDUbJwo5Yyvfa4GPBshS89qJcJA'. System.InvalidOperationException: Collection was modified; enumeration operation may not execute.

    You can try to override the PageToolbarManager

    [ExposeServices(typeof(PageToolbarManager), typeof(IPageToolbarManager))]
    [Dependency(ReplaceServices = true)]
    public class MyPageToolbarManager : PageToolbarManager
    {
    
        public MyPageToolbarManager(IServiceScopeFactory serviceScopeFactory)
            : base(serviceScopeFactory)
        {
    
        }
    
        public async override Task<PageToolbarItem[]> GetItemsAsync(PageToolbar toolbar)
        {
            if (toolbar == null)
            {
                return Array.Empty<PageToolbarItem>();
            }
            
            var contributors = toolbar.Contributors.ToList();
            if (!contributors.Any())
            {
                return Array.Empty<PageToolbarItem>();
            }
    
            using (var scope = ServiceScopeFactory.CreateScope())
            {
                var context = new PageToolbarContributionContext(scope.ServiceProvider);
    
                foreach (var contributor in contributors)
                {
                    await contributor.ContributeAsync(context);
                }
    
                return context.Items.OrderBy(i => i.Order).ToArray();
            }
        }
    }
    
Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09