{"record":{"id":"421c38e7bc473b37","repo":"abpframework/abp","slug":"could-not-find-typeof-iserviceproviderfactory-tco","errorCode":null,"errorMessage":"Could not find {typeof(IServiceProviderFactory<TContainerBuilder>).FullName} in {services}.","messagePattern":"Could not find (.+?) in (.+?)\\.","errorType":"exception","errorClass":"AbpException","httpStatus":null,"severity":"error","filePath":"framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionCommonExtensions.cs","lineNumber":81,"sourceCode":"            return (IServiceProvider)typeof(ServiceCollectionCommonExtensions)\n                .GetTypeInfo()\n                .GetMethods()\n                .Single(m => m.Name == nameof(BuildServiceProviderFromFactory) && m.IsGenericMethod)\n                .MakeGenericMethod(containerBuilderType)\n                .Invoke(null, new object?[] { services, null })!;\n        }\n\n        return services.BuildServiceProvider();\n    }\n\n    public static IServiceProvider BuildServiceProviderFromFactory<TContainerBuilder>([NotNull] this IServiceCollection services, Action<TContainerBuilder>? builderAction = null) where TContainerBuilder : notnull\n    {\n        Check.NotNull(services, nameof(services));\n\n        var serviceProviderFactory = services.GetSingletonInstanceOrNull<IServiceProviderFactory<TContainerBuilder>>();\n        if (serviceProviderFactory == null)\n        {\n            throw new AbpException($\"Could not find {typeof(IServiceProviderFactory<TContainerBuilder>).FullName} in {services}.\");\n        }\n\n        var builder = serviceProviderFactory.CreateBuilder(services);\n        builderAction?.Invoke(builder);\n        return serviceProviderFactory.CreateServiceProvider(builder);\n    }\n\n    /// <summary>\n    /// Resolves a dependency using given <see cref=\"IServiceCollection\"/>.\n    /// This method should be used only after dependency injection registration phase completed.\n    /// </summary>\n    internal static T? GetService<T>(this IServiceCollection services)\n    {\n        return services\n            .GetSingletonInstance<IAbpApplication>()\n            .ServiceProvider\n            .GetService<T>();\n    }","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/abpframework/abp/blob/7ed43b1931b9df46a50c0c59148a18645641d0df/framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionCommonExtensions.cs#L63-L99","documentation":"Thrown by BuildServiceProviderFromFactory<TContainerBuilder> when no IServiceProviderFactory<TContainerBuilder> singleton is registered. ABP uses this path to delegate provider construction to a third-party container (Autofac, etc.); if the generic factory for the expected container builder type is missing, it cannot build the provider the requested way.","triggerScenarios":"Calling services.BuildServiceProviderFromFactory<ContainerBuilder>() without having registered Autofac's ServiceProviderFactory, or requesting the wrong TContainerBuilder generic than what was registered.","commonSituations":"Using ABP's Autofac integration but forgetting services.AddAutofac() / the UseAutofac host configuration; mixing container types; calling the generic overload when a non-generic factory is present (or vice versa).","solutions":["Register the matching container factory: for Autofac, call AddAutofac() (ASP.NET Core) or configure the generic host with .UseAutofac() so an IServiceProviderFactory<ContainerBuilder> singleton is added.","Ensure the generic TContainerBuilder matches the registered factory's builder type.","If you do not use a custom container, call the non-generic BuildServiceProviderFromFactory() or services.BuildServiceProvider() instead.","Verify module load order so the container integration module runs before the build call."],"exampleFix":"// before — generic call with no Autofac factory registered\nvar provider = services.BuildServiceProviderFromFactory<ContainerBuilder>();\n\n// after — register Autofac first\nbuilder.Host.UseAutofac(); // or services.AddAutofac();\nvar provider = services.BuildServiceProviderFromFactory<ContainerBuilder>();","handlingStrategy":"validation","validationCode":"// Confirm the container factory is registered before building via the generic path\nvar factory = services.GetSingletonInstanceOrNull<IServiceProviderFactory<ContainerBuilder>>();\nif (factory == null)\n    throw new InvalidOperationException(\"Autofac factory missing — call builder.Host.UseAutofac() first.\");\nvar provider = services.BuildServiceProviderFromFactory<ContainerBuilder>();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Register the container integration (AddAutofac / UseAutofac) before BuildServiceProviderFromFactory<T>.","Match the generic TContainerBuilder to the registered factory's builder type.","Use the non-generic BuildServiceProvider() when no custom container is needed."],"tags":["dependency-injection","autofac","container","abp-core","startup"],"backgroundTag":null,"analyzedSha":"7ed43b1931b9df46a50c0c59148a18645641d0df","analyzedAt":"2026-08-13T16:26:11.351Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}