Activities of "Anawaz"

I increased the delay from 5000 to 15000 and now it is working. It seems Database was no ready before it runs dataseed. Updated code.

 private async Task MigrateAndSeedForTenantAsync(
     Guid tenantId,
     string adminEmail,
     string adminPassword)
 {
     try
     {
         using (_currentTenant.Change(tenantId))
         {
             await Task.Delay(15000);
             // Create database tables if needed
             using (var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: false))
             {
                 var tenantConfiguration = await _tenantStore.FindAsync(tenantId);
                 if (tenantConfiguration?.ConnectionStrings != null &&
                     !tenantConfiguration.ConnectionStrings.Default.IsNullOrWhiteSpace())
                 {
                     foreach (var migrator in _dbSchemaMigrators)
                     {
                         await migrator.MigrateAsync();
                     }
                 }

                 await uow.CompleteAsync();
             }
             await Task.Delay(15000);
             // Seed data
             using (var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: true))
             {
                 await _dataSeeder.SeedAsync(
                     new DataSeedContext(tenantId)
                         .WithProperty(IdentityDataSeedContributor.AdminEmailPropertyName, adminEmail)
                         .WithProperty(IdentityDataSeedContributor.AdminPasswordPropertyName, adminPassword)
                 );

                 await uow.CompleteAsync();
             }
         }
     }
     catch (Exception ex)
     {
         _logger.LogException(ex);
     }
 }

While creating new Tenant Data Seeding fails. Code is working when I go step by step during debugging however it doesn't work while application is running. I tried to add delay however that still didn't worked.

  • ABP Framework version: v8.3.0
  • UI Type: Blazor Server
  • Database System: EF Core (SQL Server)
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes
  • Exception message and full stack trace:
2024-09-18 10:10:22.858 +05:00 [ERR] Internal Server Error
Volo.Abp.Http.Client.AbpRemoteCallException: Internal Server Error
   at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.ThrowExceptionForResponseAsync(HttpResponseMessage response)
   at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.RequestAsync(ClientProxyRequestContext requestContext)
   at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.RequestAsync[T](ClientProxyRequestContext requestContext)
   at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.RequestAsync[T](String methodName, ClientProxyRequestTypeValue arguments)
   at Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ClientProxies.AbpApplicationLocalizationClientProxy.GetAsync(ApplicationLocalizationRequestDto input)
   at Volo.Abp.AspNetCore.Mvc.Client.MvcCachedApplicationConfigurationClient.GetRemoteConfigurationAsync()
   at Volo.Abp.AspNetCore.Mvc.Client.MvcCachedApplicationConfigurationClient.<GetAsync>b__19_0()
   at Volo.Abp.Caching.DistributedCache`2.GetOrAddAsync(TCacheKey key, Func`1 factory, Func`1 optionsFactory, Nullable`1 hideErrors, Boolean considerUow, CancellationToken token)
   at Volo.Abp.AspNetCore.Mvc.Client.MvcCachedApplicationConfigurationClient.GetAsync()
   at Volo.Abp.AspNetCore.Mvc.Client.RemoteSettingProvider.GetOrNullAsync(String name)
   at Volo.Abp.Settings.SettingProviderExtensions.GetAsync[T](ISettingProvider settingProvider, String name, T defaultValue)
   at Volo.Abp.Identity.AbpIdentityOptionsManager.OverrideOptionsAsync(String name, IdentityOptions options)
   at Volo.Abp.Identity.IdentityDataSeeder.SeedAsync(String adminEmail, String adminPassword, Nullable`1 tenantId, String adminUserName)
   at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
   at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
   at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
   at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
   at Volo.Abp.Data.DataSeeder.SeedAsync(DataSeedContext context)
   at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous(IInvocation invocation, IInvocationProceedInfo proceedInfo)
   at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapter.ProceedAsync()
   at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
   at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
   at ProjectName.Data.OnyxTenantDatabaseMigrationHandler.MigrateAndSeedForTenantAsync(Guid tenantId, String adminEmail, String adminPassword) in F:\ProjectName\src\ProjectName.Domain\Data\OnyxTenantDatabaseMigrationHandler.cs:line 116
  • Steps to reproduce the issue: Create New Tenant with Separate Database
  • Code
private async Task MigrateAndSeedForTenantAsync(
    Guid tenantId,
    string adminEmail,
    string adminPassword)
{
    try
    {
        using (_currentTenant.Change(tenantId))
        {
            await Task.Delay(5000);
            // Create database tables if needed
            using (var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: false))
            {
                var tenantConfiguration = await _tenantStore.FindAsync(tenantId);
                if (tenantConfiguration?.ConnectionStrings != null &&
                    !tenantConfiguration.ConnectionStrings.Default.IsNullOrWhiteSpace())
                {
                    foreach (var migrator in _dbSchemaMigrators)
                    {
                        await migrator.MigrateAsync();
                    }
                }

                await uow.CompleteAsync();
            }
            await Task.Delay(5000);
            // Seed data
            using (var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: true))
            {
                await _dataSeeder.SeedAsync(
                    new DataSeedContext(tenantId)
                        .WithProperty(IdentityDataSeedContributor.AdminEmailPropertyName, adminEmail)
                        .WithProperty(IdentityDataSeedContributor.AdminPasswordPropertyName, adminPassword)
                );

                await uow.CompleteAsync();
            }
        }
    }
    catch (Exception ex)
    {
        _logger.LogException(ex);
    }
}
Showing 1 to 2 of 2 entries
Made with ❤️ on ABP v9.0.0-preview Updated on September 19, 2024, 10:13