abpframework/abp · error · AbpException
Could not find an implementation of {typeof(IConfiguration).
Error message
Could not find an implementation of {typeof(IConfiguration).AssemblyQualifiedName} in the service collection. What it means
Thrown by ServiceCollectionConfigurationExtensions.GetConfiguration when no IConfiguration is resolvable from the service collection: neither a HostBuilderContext with a non-null Configuration nor a directly registered IConfiguration singleton exists. ABP's configuration access requires one of these to be present during startup.
Source
Thrown at framework/src/Volo.Abp.Core/Microsoft/Extensions/DependencyInjection/ServiceCollectionConfigurationExtensions.cs:20
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Volo.Abp;
namespace Microsoft.Extensions.DependencyInjection;
public static class ServiceCollectionConfigurationExtensions
{
public static IServiceCollection ReplaceConfiguration(this IServiceCollection services, IConfiguration configuration)
{
return services.Replace(ServiceDescriptor.Singleton<IConfiguration>(configuration));
}
[NotNull]
public static IConfiguration GetConfiguration(this IServiceCollection services)
{
return services.GetConfigurationOrNull() ??
throw new AbpException("Could not find an implementation of " + typeof(IConfiguration).AssemblyQualifiedName + " in the service collection.");
}
[CanBeNull]
public static IConfiguration? GetConfigurationOrNull(this IServiceCollection services)
{
var hostBuilderContext = services.GetSingletonInstanceOrNull<HostBuilderContext>();
if (hostBuilderContext?.Configuration != null)
{
return hostBuilderContext.Configuration as IConfigurationRoot;
}
return services.GetSingletonInstanceOrNull<IConfiguration>();
}
}
View on GitHub (pinned to 7ed43b1931)
Solutions
- Use the generic host (AbpApplicationFactory.CreateAsync with a host, or AbpApplicationCreationOptions to set configuration) so IConfiguration is wired automatically.
- Manually register: services.ReplaceConfiguration(new ConfigurationBuilder().Build().AddJsonFile(...)) or services.AddObjectAccessor(hostBuilderContext).
- If configuration is optional, use GetConfigurationOrNull() and handle the null.
- Ensure ReplaceConfiguration is called when you supply your own IConfiguration instance.
Example fix
// before — no configuration registered
var cfg = services.GetConfiguration();
// after — register IConfiguration explicitly
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true)
.Build();
services.ReplaceConfiguration(configuration);
var cfg = services.GetConfiguration(); Defensive patterns
Strategy: validation
Validate before calling
// Use the OrNull variant and seed configuration explicitly when absent
var cfg = services.GetConfigurationOrNull();
if (cfg == null)
{
cfg = new ConfigurationBuilder().AddJsonFile("appsettings.json", optional: true).Build();
services.ReplaceConfiguration(cfg);
} Prevention
- Use the generic host so IConfiguration is wired automatically.
- Call services.ReplaceConfiguration(myConfig) when supplying your own IConfiguration.
- Use GetConfigurationOrNull() when configuration may be absent.
When it happens
Trigger: Calling services.GetConfiguration() outside a generic host/IHostBuilder context without manually registering an IConfiguration, or before ReplaceConfiguration/HostBuilderContext is available.
Common situations: Building an ABP application without the generic host (e.g. a console app that creates AbpApplication directly and forgets to register IConfiguration); unit-testing ConfigureServices in isolation without seeding configuration; calling GetConfiguration before the host builder has populated HostBuilderContext.
Related errors
- No BLOB Storage provider was registered! At least one provid
- Could not find singleton service: {typeof(T).AssemblyQualifi
- Could not find {typeof(IServiceProviderFactory<TContainerBui
- An object accessor is registered before for type: {typeof(T)
- Could not find an object of {typeof(T).AssemblyQualifiedName
AI-assisted analysis of abpframework/abp@7ed43b1931 (2026-08-13).
Data as JSON: /api/errors/d7c60c2f3610e9ed.
Report an issue: GitHub.