Base solution for your next web application
Open Closed

Castle.MicroKernel.ComponentActivator.ComponentActivatorException #7825


User avatar
0
ale1648604090 created

hello,One of my new projects went wrong while doing dependency injection.

The error messageļ¼š

Castle.MicroKernel.ComponentActivator.ComponentActivatorException
  HResult=0x80131500
  Message=ComponentActivator: could not instantiate Microsoft.AspNetCore.Mvc.Internal.MvcEndpointDataSource
  Source=Castle.Windsor
  StackTrace:
   at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstanceCore(ConstructorCandidate constructor, Object[] arguments, Type implType)
   at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstance(CreationContext context, ConstructorCandidate constructor, Object[] arguments)
   at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context)
   at Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context, Burden burden)
   at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext context, Boolean trackedExternally)
   at Castle.MicroKernel.Lifestyle.SingletonLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy)
   at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden)
   at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired)
   at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, Arguments additionalArguments, IReleasePolicy policy, Boolean ignoreParentContext)
   at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.ResolveAll(Type service, Arguments arguments, IReleasePolicy policy)
   at Castle.Windsor.MsDependencyInjection.ScopedWindsorServiceProvider.ResolveInstanceOrNull(Type serviceType, Boolean isOptional)
   at Castle.Windsor.MsDependencyInjection.ScopedWindsorServiceProvider.GetServiceInternal(Type serviceType, Boolean isOptional)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.AspNetCore.Builder.MvcApplicationBuilderExtensions.UseMvc(IApplicationBuilder app, Action`1 configureRoutes)
   at GollumPay.Web.PayWeb.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env) in D:\Project\GollumPay\GollumPayTrunk_1.0\src\GollumPay.Web.PayWeb\Startup\Startup.cs:line 88

Exception 1: Exception: Could not instantiate Microsoft.AspNetCore.Mvc.Internal.MvcEndpointDataSource.

Exception 2: TargetInvocationException: Exception has been thrown by the target of an invocation.

Exception 3: ComponentNotFoundException: No component for supporting the service Abp.AspNetCore.Configuration.AbpAspNetCoreConfiguration was found

my Startup code:

        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            return services.AddAbp<GollumPayWebPayWebModule>();
        }
        
    [DependsOn(
        typeof(GollumPayWebCoreModule)
    )]
    public class GollumPayWebPayWebModule : AbpModule
    {
        private readonly IHostingEnvironment _env;
        private readonly IConfigurationRoot _appConfiguration;

        public GollumPayWebPayWebModule(
            IHostingEnvironment env)
        {
            _env = env;
            _appConfiguration = env.GetAppConfiguration();
        }

        public override void PreInitialize()
        {
            Configuration.Modules.AspNetZero().LicenseCode = _appConfiguration["AbpZeroLicenseCode"];
        }

        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(typeof(GollumPayWebPayWebModule).GetAssembly());
        }

    }
    ```

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

    Hi,

    You need to depnd on AbpAspNetCoreModule module.

    [DependsOn(
        typeof(GollumPayWebCoreModule),
        typeof(AbpAspNetCoreModule)
    )]
    public class GollumPayWebPayWebModule : AbpModule
    {
        private readonly IHostingEnvironment _env;
        private readonly IConfigurationRoot _appConfiguration;
    
        public GollumPayWebPayWebModule(
            IHostingEnvironment env)
        {
            _env = env;
            _appConfiguration = env.GetAppConfiguration();
        }
    
        public override void PreInitialize()
        {
            Configuration.Modules.AspNetZero().LicenseCode = _appConfiguration["AbpZeroLicenseCode"];
        }
    
        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(typeof(GollumPayWebPayWebModule).GetAssembly());
        }
    
    }