Base solution for your next web application
Open Closed

Object disposed #2780


User avatar
0
sagreven created

Perhaps it's a question which is handled more often. But I'm not sure what happened:

  • I just upgrade to Abp v1.5.1 using NuGet

First issue:

I have the following code:

using (_unitOfWorkManager.Current.DisableFilter(AbpDataFilters.MayHaveTenant))
{
	if (await _userManager.UserExist(feed.UserId))
	{
		user = await _userManager.GetUserByIdAsync(feed.UserId);

The function is declared as

[UnitOfWork]
public async Task<IEnumerable

Get UserByIdAsync gives me an disposed error while _userMananger.UserExist runs fine.

Second issue: My code looks like the following:

using (_unitOfWorkManager.Current.SetFilterParameter(AbpDataFilters.MayHaveTenant, 
     AbpDataFilters.Parameters.TenantId, tenantId))
				{

					CheckErrors(await _userManager.AddToRoleAsync(userId, roleName));

The function is defined as

[UnitOfWork]
		public async Task AddToRole

Here I'm getting the error that the user is already taken ;) ;) Inserting manually the role works as expected.

I think i missed something important but I can't figured out what it is

Please help


2 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Do you call both methods with await ? If so, please share your full source code or at least the related parts for reproducing the error.

    Thanks.

  • User Avatar
    0
    sagreven created

    This is a service function. So nothing special. The commentend function shows the workaround.

    Edit: I think I have a general problem with the UOW because I also discovered in other functions that it's not possible to disable filter. How can I debug this? I tried to disable the IMustHaveTenant filter but than while debugging the table is even not resolveable in the debugger mode.

    [UnitOfWork]
    		public async Task AddToRole(long userId, string roleName, int? tenantId)
    		{
    			if (tenantId == null)
    				CheckErrors(await _userManager.AddToRoleAsync(userId, roleName));
    			else
    			{
    				using (_unitOfWorkManager.Current.SetFilterParameter(AbpDataFilters.MayHaveTenant, AbpDataFilters.Parameters.TenantId, tenantId))
    				{
    					// Todo: Temporary fix
    					//var role = await _roleManager.GetRoleByNameAsync(roleName);
    					//if (await _userRoleRepository.FirstOrDefaultAsync(x => x.RoleId == role.Id && x.TenantId == (int)tenantId) != null)
    					//	throw new UserFriendlyException("Permission already assigned.");
    					//await _userRoleRepository.InsertAsync(new UserRole(tenantId, userId, role.Id));
    					await _sessionAppService.ResetAllCaches();
    					CheckErrors(await _userManager.AddToRoleAsync(userId, roleName));
    				}
    			}
    		}