abpframework/abp · error · AbpException

Could not find {typeof(IServiceProviderFactory<TContainerBui

Error message

Could not find {typeof(IServiceProviderFactory<TContainerBuilder>).FullName} in {services}.

What it means

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.

Source

Thrown at framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionCommonExtensions.cs:81

            return (IServiceProvider)typeof(ServiceCollectionCommonExtensions)
                .GetTypeInfo()
                .GetMethods()
                .Single(m => m.Name == nameof(BuildServiceProviderFromFactory) && m.IsGenericMethod)
                .MakeGenericMethod(containerBuilderType)
                .Invoke(null, new object?[] { services, null })!;
        }

        return services.BuildServiceProvider();
    }

    public static IServiceProvider BuildServiceProviderFromFactory<TContainerBuilder>([NotNull] this IServiceCollection services, Action<TContainerBuilder>? builderAction = null) where TContainerBuilder : notnull
    {
        Check.NotNull(services, nameof(services));

        var serviceProviderFactory = services.GetSingletonInstanceOrNull<IServiceProviderFactory<TContainerBuilder>>();
        if (serviceProviderFactory == null)
        {
            throw new AbpException($"Could not find {typeof(IServiceProviderFactory<TContainerBuilder>).FullName} in {services}.");
        }

        var builder = serviceProviderFactory.CreateBuilder(services);
        builderAction?.Invoke(builder);
        return serviceProviderFactory.CreateServiceProvider(builder);
    }

    /// <summary>
    /// Resolves a dependency using given <see cref="IServiceCollection"/>.
    /// This method should be used only after dependency injection registration phase completed.
    /// </summary>
    internal static T? GetService<T>(this IServiceCollection services)
    {
        return services
            .GetSingletonInstance<IAbpApplication>()
            .ServiceProvider
            .GetService<T>();
    }

View on GitHub (pinned to 7ed43b1931)

Solutions

  1. 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.
  2. Ensure the generic TContainerBuilder matches the registered factory's builder type.
  3. If you do not use a custom container, call the non-generic BuildServiceProviderFromFactory() or services.BuildServiceProvider() instead.
  4. Verify module load order so the container integration module runs before the build call.

Example fix

// before — generic call with no Autofac factory registered
var provider = services.BuildServiceProviderFromFactory<ContainerBuilder>();

// after — register Autofac first
builder.Host.UseAutofac(); // or services.AddAutofac();
var provider = services.BuildServiceProviderFromFactory<ContainerBuilder>();
Defensive patterns

Strategy: validation

Validate before calling

// Confirm the container factory is registered before building via the generic path
var factory = services.GetSingletonInstanceOrNull<IServiceProviderFactory<ContainerBuilder>>();
if (factory == null)
    throw new InvalidOperationException("Autofac factory missing — call builder.Host.UseAutofac() first.");
var provider = services.BuildServiceProviderFromFactory<ContainerBuilder>();

Prevention

When it happens

Trigger: Calling services.BuildServiceProviderFromFactory<ContainerBuilder>() without having registered Autofac's ServiceProviderFactory, or requesting the wrong TContainerBuilder generic than what was registered.

Common situations: 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).

Related errors


AI-assisted analysis of abpframework/abp@7ed43b1931 (2026-08-13). Data as JSON: /api/errors/421c38e7bc473b37. Report an issue: GitHub.