Ends in:
3 DAYS
6 HRS
42 MIN
9 SEC
Ends in:
3 D
6 H
42 M
9 S
Open Closed

Microservice MongoDB IdentityServerDataSeeder.SeedAsync() thorws "Value cannot be null. (Parameter 'connectionString')" #3295


User avatar
0
jeffbuot created
  • ABP Framework version: v5.3.0
  • Project type: Abp Microservice Template
  • DB provider: MongoDB
  • Exception message and stack trace:
System.ArgumentNullException: Value cannot be null. (Parameter 'connectionString')
   at MongoDB.Driver.Core.Misc.Ensure.IsNotNull[T](T value, String paramName)
   at MongoDB.Driver.Core.Configuration.ConnectionString..ctor(String connectionString, Boolean isInternalRepresentation, IDnsResolver dnsResolver)
   at MongoDB.Driver.Core.Configuration.ConnectionString..ctor(String connectionString)
   at MongoDB.Driver.MongoUrlBuilder.Parse(String url)
   at MongoDB.Driver.MongoUrlBuilder..ctor(String url)
   at MongoDB.Driver.MongoUrl..ctor(String url)
   at Volo.Abp.Uow.MongoDB.UnitOfWorkMongoDbContextProvider`1.GetDbContextAsync(CancellationToken cancellationToken)
   at Volo.Abp.Domain.Repositories.MongoDB.MongoDbRepository`2.GetMongoQueryableAsync[TOtherEntity](CancellationToken cancellationToken)
   at Volo.Abp.Identity.MongoDB.MongoIdentityClaimTypeRepository.AnyAsync(String name, Nullable`1 ignoredId, CancellationToken cancellationToken)
   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.IdentityServer.IdentityResources.IdentityResourceDataSeeder.AddClaimTypeIfNotExistsAsync(String claimType)
   at Volo.Abp.IdentityServer.IdentityResources.IdentityResourceDataSeeder.CreateStandardResourcesAsync()
   at ProjectName.IdentityService.DbMigrations.IdentityServerDataSeeder.SeedAsync() in /Users/jeffb/Projects/projectname/services/identity/src/ProjectName.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs:line 72
   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.IdentityService.DbMigrations.IdentityServiceDataSeeder.SeedAsync(Nullable`1 tenantId, String adminEmail, String adminPassword) in /Users/jeffb/Projects/projectname/services/identity/src/PorjectName.IdentityService.HttpApi.Host/DbMigrations/IdentityServiceDataSeeder.cs:line 64
  • Steps to reproduce the issue:"
  • Create new microservice project from abp suite
  • Change the database context of all microservices from efcore sqlserver to mongo db by following this steps from: https://docs.abp.io/en/commercial/latest/guides/microservice-mongodb
  • Run the ProjectName.IdentityService.HttpApi.Host

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

    hi

    It seems that the connection string is not getting correctly.

    You can debug the connectionStringResolver try to get the connection string.

    var connectionStringResolver = ServiceProvider.GetRequiredService<IConnectionStringResolver>();
    
  • User Avatar
    0
    jeffbuot created

    Hi,

    I checked the value of connectionStringResolver and this is what I got:

    Exception occurs on await _identityServerDataSeeder.SeedAsync(); I already added the [ConnectionStringName(IdentityServiceDbProperties.ConnectionStringName)] attribute to IdentityServiceMongoDbContext

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you share the source code with me? liming.ma@volosoft.com

  • User Avatar
    0
    jeffbuot created

    hi

    Can you share the source code with me? liming.ma@volosoft.com

    I invited you to a private github repo.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    ok, I will check.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Add MyMultiTenantConnectionStringResolver to your CMVPoint.IdentityService.MongoDB project, I will fix this in 5.3 patch version.

    using System;
    using System.Threading.Tasks;
    using Microsoft.Extensions.Options;
    using Volo.Abp.Data;
    using Volo.Abp.DependencyInjection;
    using Volo.Abp.MultiTenancy;
    
    namespace CMVPoint.IdentityService.MongoDb;
    
    [Dependency(ReplaceServices = true)]
    public class MyMultiTenantConnectionStringResolver : MultiTenantConnectionStringResolver
    {
        public MyMultiTenantConnectionStringResolver(
            IOptionsMonitor<AbpDbConnectionOptions> options,
            ICurrentTenant currentTenant,
            IServiceProvider serviceProvider)
            : base(options, currentTenant, serviceProvider)
        {
        }
    
        public override Task<string> ResolveAsync(string connectionStringName = null)
        {
            if (connectionStringName == "Volo.Abp.Identity.MongoDB.IdentityProMongoDbContext")
            {
                return base.ResolveAsync("AbpIdentity");
            }
            return base.ResolveAsync(connectionStringName);
        }
    
        public override string Resolve(string connectionStringName = null)
        {
            if (connectionStringName == "Volo.Abp.Identity.MongoDB.IdentityProMongoDbContext")
            {
                return base.Resolve("AbpIdentity");
            }
    
            return base.Resolve(connectionStringName);
        }
    }
    
    
  • User Avatar
    0
    jeffbuot created

    hi

    Add MyMultiTenantConnectionStringResolver to your CMVPoint.IdentityService.MongoDB project, I will fix this in 5.3 patch version.

    using System; 
    using System.Threading.Tasks; 
    using Microsoft.Extensions.Options; 
    using Volo.Abp.Data; 
    using Volo.Abp.DependencyInjection; 
    using Volo.Abp.MultiTenancy; 
     
    namespace CMVPoint.IdentityService.MongoDb; 
     
    [Dependency(ReplaceServices = true)] 
    public class MyMultiTenantConnectionStringResolver : MultiTenantConnectionStringResolver 
    { 
        public MyMultiTenantConnectionStringResolver( 
            IOptionsMonitor<AbpDbConnectionOptions> options, 
            ICurrentTenant currentTenant, 
            IServiceProvider serviceProvider) 
            : base(options, currentTenant, serviceProvider) 
        { 
        } 
     
        public override Task<string> ResolveAsync(string connectionStringName = null) 
        { 
            if (connectionStringName == "Volo.Abp.Identity.MongoDB.IdentityProMongoDbContext") 
            { 
                return base.ResolveAsync("AbpIdentity"); 
            } 
            return base.ResolveAsync(connectionStringName); 
        } 
     
        public override string Resolve(string connectionStringName = null) 
        { 
            if (connectionStringName == "Volo.Abp.Identity.MongoDB.IdentityProMongoDbContext") 
            { 
                return base.Resolve("AbpIdentity"); 
            } 
     
            return base.Resolve(connectionStringName); 
        } 
    } 
     
    

    Hi, thanks issue has been resolved.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 02, 2024, 12:35