Open Closed

Blazor WASM: System.ObjectDisposedException: Cannot access a disposed object of dependency injection replacement scenario of UserManagement #4392


0
Sturla created

Sorry for the title but I´m unsure what to call this

But if I navigate to and from the user management dropdown (to some other page) I get the following exception with a error message and UI popup.

blazor.webassembly.js:1 
       
 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Cannot access a disposed object.
      Object name: 'BSR.Beinni.Blazor.Pages.BsrUserManagement'.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'BSR.Beinni.Blazor.Pages.BsrUserManagement'.
   at Microsoft.AspNetCore.Components.OwningComponentBase.get_ScopedServices()
   at Volo.Abp.AspNetCore.Components.AbpComponentBase.LazyGetRequiredService[IObjectMapper](Type serviceType, IObjectMapper& reference)
   at Volo.Abp.AspNetCore.Components.AbpComponentBase.get_ObjectMapper()
   at Volo.Abp.Identity.Pro.Blazor.Pages.Identity.UserManagement.GetOrganizationUnitsAsync(ICollection`1 selectedOuIds)
   at Volo.Abp.Identity.Pro.Blazor.Pages.Identity.UserManagement.OnInitializedAsync()
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

Here is the code

namespace BSR.Beinni.Blazor.Pages
{
    [ExposeServices(typeof(UserManagement))]
    [Dependency(ReplaceServices = true)]
    public class BsrUserManagement : UserManagement
    {
        protected override async ValueTask SetEntityActionsAsync()
        {
            await base.SetEntityActionsAsync();

            var indexClaim = EntityActions.Get<UserManagement>().FindIndex(x => x.Text == "Claims");
            EntityActions.Get<UserManagement>().RemoveAt(indexClaim);
        }
    }
}

I thought this might be related to Use Default ComponentActivator for Blazorise

so I added this

context.Services.Replace(ServiceDescriptor.Scoped<IComponentActivator, ComponentActivator>());`
in my `BeinniBlazorModule.ConfigureServices()

but that doesn´t solve it

What should I do here?

  • ABP Framework version: v7.0.1
  • UI type: Blazor WASM
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes

6 Answer(s)
  • 0
    Sturla created

    Any news on this liangshiwei?

    Should be super easy to test on your end and see it fail, that is if its not something else I’m doing wrong (and you can hopefully help me with)

  • 0
    liangshiwei created
    Support Team

    Hi,

    I will check it out.

  • 0
    Sturla created

    Hi

    Do you have a workaround for me or is this a bug and if so will it be fixed in 7.0.2.

  • 0
    liangshiwei created
    Support Team

    Hi,

    Sorry for later, I could not reproduce the problem, can you share a project that can reproduce the problem with me? [email protected]

  • 0
    Sturla created

    I created file new project (that will send you now) where I could reproduce this.

    Just navigate between Dashboard and Users few times (3-5x rather fast (doesn´t have to be super fast) and you will see this error

  • 0
    liangshiwei created
    Support Team

    Hi,

    We will fix it in the next patch version:

    You can try this:

    MyUserManagement.razor.cs

    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(UserManagement))]
    public partial class MyUserManagement : UserManagement
    {
        protected override async Task OnInitializedAsync()
        {
            await SetPermissionsAsync();
            await SetEntityActionsAsync();
            await SetTableColumnsAsync();
            await InvokeAsync(StateHasChanged);
    
            Roles = (await AppService.GetAssignableRolesAsync()).Items;
            RequireConfirmedEmail = await SettingProvider.IsTrueAsync(IdentitySettingNames.SignIn.RequireConfirmedEmail);
        }
    
        protected virtual async Task OnAdvancedFilterSectionClick()
        {
            ShowAdvancedFilters = !ShowAdvancedFilters;
    
            if (ShowAdvancedFilters)
            {
                await GetOrganizationUnitsAsync();
            }
        }
    }
    

    MyUserManagement.razor

    https://gist.github.com/realLiangshiwei/bc88b4c7a9b1d7757084da05f179e5fe