Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

A task was canceled. #10903


User avatar
0
kansoftware created

Prerequisites

  • What is your product version?
  • 8.5
  • What is your product type (Angular or MVC)?
  • MVC
  • What is product framework type (.net framework or .net core)?
  • .net core

this following line giving error in this function RegisterAsync - and error is A task was canceled.

Location : CDP.Core\Authorization\Users\UserRegistrationManager.cs:

  • await _userManager.InitializeOptionsAsync(tenantID);*

This issue occurring while we are creating user by api and setting manuallly tenantid in abp session. But Its working fine on web.

Here is error log

A task was canceled. at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.AsyncEnumerator.InitializeReaderAsync(DbContext _, Boolean result, 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.QueryingEnumerable1.AsyncEnumerator.MoveNextAsync() at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync[TSource](IAsyncEnumerable1 asyncEnumerable, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync[TSource](IAsyncEnumerable1 asyncEnumerable, CancellationToken cancellationToken) at Abp.EntityFrameworkCore.Repositories.EfCoreRepositoryBase3.FirstOrDefaultAsync(Expression1 predicate) at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation) at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation) at Microsoft.AspNetCore.Identity.UserManager1.FindByNameAsync(String userName) at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation) at Abp.Authorization.Users.AbpUserManager2.CheckDuplicateUsernameOrEmailAddressAsync(Nullable1 expectedUserId, String userName, String emailAddress) at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation) at Abp.Authorization.Users.AbpUserManager2.CreateAsync(TUser user) at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation) at Microsoft.AspNetCore.Identity.UserManager1.CreateAsync(TUser user, String password) at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation) at CDP.Authorization.Users.UserRegistrationManager.RegisterAsync(String name, String surname, String emailAddress, String userName, String plainPassword, Boolean isEmailConfirmed, String emailActivationLink, Boolean IsCustomerRole, Nullable1 tenantID) in D:\Projects\SprngNew\branches\dev\src\CDP.Core\Authorization\Users\UserRegistrationManager.cs:line 109 at CDP.Authorization.Accounts.AccountAppService.RegisterAPI(RegisterInput input) in D:\Projects\SprngNew\branches\dev\src\CDP.Application\Authorization\Accounts\AccountAppService.cs:line 571 at Abp.Authorization.AuthorizationInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation) at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation) at Abp.Auditing.AuditingInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation) at Abp.Auditing.AuditingInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation) at Abp.Runtime.Validation.Interception.ValidationInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation) at CDP.Stripe.ShopifyAppService.CreateAsync(Order order, CancellationToken cancellationToken) in D:\Projects\SprngNew\branches\dev\src\CDP.Application\Shopify\ShopifyAppService.cs:line 232 at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous(IInvocation invocation) at Abp.Auditing.AuditingInterceptor.InternalInterceptAsynchronous(IInvocation invocation) at Abp.Runtime.Validation.Interception.ValidationInterceptor.InternalInterceptAsynchronous(IInvocation invocation) at lambda_method(Closure , Object ) at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult() at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.

For more refference in code

 using (var unitOfWork = _unitOfWorkManager.Begin(TransactionScopeOption.RequiresNew))
                        {
                         

                            using (_unitOfWorkManager.Current.SetTenantId(inputOrder.TenantID))
                            {
                               
                                using (_iSession.Use(inputOrder.TenantID, inputOrder.AdminUserId))
                                {
                                   

                                    var id = AbpSession.TenantId;
                                 
                                    model.TenantId = inputOrder.TenantID;                                
                                    model.Password = "123456";
                                    UserID =await _accountAppService.RegisterAPI(model);                                 
                                    unitOfWork.Complete();
                                }
                            }

                        }

We setting tenantid manually and RegisterAsync function is calling in _accountAppService.RegisterAPI service. RegisterAPI code in bellow

   public async Task&lt;long&gt; RegisterAPI(RegisterInput input)
        {
            //if (UseCaptchaOnRegistration())
            //{
            //    await RecaptchaValidator.ValidateAsync(input.CaptchaResponse);
            //}

            if (AbpSession != null) input.TenantId = AbpSession.TenantId;

            var user = await _userRegistrationManager.RegisterAsync(
                input.Name,
                input.Surname,
                input.EmailAddress,
                input.UserName,
                input.Password,
                true,
                AppUrlService.CreateEmailActivationUrlFormat(input.TenantId),
                true,
                input.TenantId
            );

            CreateOrEditUserDetailDto userdetail = new CreateOrEditUserDetailDto();

            userdetail.UserID = user.Id;
            userdetail.FirstName = input.Name;
            userdetail.LastName = input.Surname;
            userdetail.CountryID = null;
            userdetail.TimeZoneName = "";
            userdetail.IsTenant = false;
            userdetail.City = "";
            userdetail.StateID = null;
            userdetail.Phone = "";
            userdetail.ImageDataID = null;
            userdetail.CoachCategoryMap = new CreateOrEditCoachCategoryMappingDto();
            userdetail.TenantPurposeMap = new CreateOrEditTenantPurposeMappingDto();
            userdetail.TimeZoneName = await _userDetailsAppService.GetTenantTimeZone(Convert.ToInt32(AbpSession.TenantId));


            await _userDetailsAppService.CreateOrEdit(userdetail);

            //Getting tenant-specific settings
            var isEmailConfirmationRequiredForLogin = await SettingManager.GetSettingValueAsync&lt;bool&gt;(AbpZeroSettingNames.UserManagement.IsEmailConfirmationRequiredForLogin);

            return user.Id;
        }

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

    Hi @kansoftware

    Could you share full source code of the class _accountAppService and ShopifyAppService with [email protected] ? I assume ShopifyAppService contains the first code block you have shared.

    Thanks,

  • User Avatar
    0
    kansoftware created

    Hi, My requirement is to register a client with specific tenant without login with any user. I have changed my code as following:

    still getting error (A task was canceled) in _userRegistrationManager.RegisterAsync (code is same as default)

    using (_unitOfWorkManager.Current.SetTenantId(2033)) { using (var unitOfWork = _unitOfWorkManager.Begin(TransactionScopeOption.RequiresNew)) {

                        Logger.Info("1. Shopify EmailAddress : "+ order.Customer.Email);
                        using (_iSession.Use(2033, null))
                        {
                            //var param1 = new ImpersonateInput();
                            //param1.TenantId = 2033;
                            //param1.UserId = 32878;
                            //await AutoLoginClient(param1);
    
    
                            RegisterViewModel model = new RegisterViewModel();
                            model.Name = order.Customer.FirstName;
                            model.Surname = order.Customer.LastName;
                            model.EmailAddress = order.Customer.Email;
    
                            model.Password = "123456";//await _userManager.CreateRandomPassword();
    
    
                            model.UserName = model.EmailAddress;
                            try
                            {
    
                                Logger.Info("2. Shopify EmailAddress : " + order.Customer.Email);
                                var user = await _userRegistrationManager.RegisterAsync(
                                    model.Name,
                                    model.Surname,
                                    model.EmailAddress,
                                    model.UserName,
                                    model.Password,
                                    true,
                                    _appUrlService.CreateEmailActivationUrlFormat(AbpSession.TenantId),
                                    true
                                );
                                Logger.Info("3.1 Shopify EmailAddress : " + order.Customer.Email);
                                await CurrentUnitOfWork.SaveChangesAsync(); //To get new user's Id.
                                Logger.Info("3.1 Shopify EmailAddress : user.id : " + user.Id);
                            }
                            catch (Exception e)
                            {
                                Logger.Info(" Shopify Exception Message: " + e.Message);
                                Logger.Info(" Shopify Exception InnerException: " + e.InnerException);
                            }
    
    
                            if (unitOfWork != null)
                                unitOfWork.Complete();
                        }
                    }
                }
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Could you remove TransactionScopeOption.RequiresNew and use unitOfWork.CompleteAsync(); instead of unitOfWork.Complete(); ?

  • User Avatar
    0
    kansoftware created

    Hi,

    We are using following controller and while hitting register function from Postman it is working totally fine on local as well on IIS hosted application and user is created for the tenant But in case we hit the same from IIS hosted application hit from shopify webhook it gives error

    I have shared the details on email with all the request response and code attached

    Regards, Harshit

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @kansoftware

    Thanks. We can continue via email for this problem.