MassTransit/MassTransit · error · ConfigurationException
No bus instances found
Error message
No bus instances found
What it means
Thrown by AddMassTransitInMemoryTestHarness when it resolves the test harness from the DI container and cannot find any IBusInstance in the provider (neither IEnumerable<IBusInstance> nor a single IBusInstance). The harness registration expects the bus to have already been configured and registered; without a bus instance there is no InMemoryTestHarnessBusInstance to serve the harness from. It is a ConfigurationException signalling the container was not configured as the testing extensions require.
Solutions
- Ensure AddMassTransitTestHarness (or AddMassTransitInMemoryTestHarness) is called on the same IServiceCollection that also configures a bus via AddMassTransit with AddBus / UsingInMemory, so IBusInstance registrations exist.
- Build the provider and resolve InMemoryTestHarness after the bus configuration; do not resolve from a freshly created or empty ServiceProvider.
- Verify MassTransit.TestFramework / MassTransit.TestFramework (testing) package versions match the core MassTransit package version.
- Check that no code removes or replaces the IBusInstance registration in the container.
Example fix
// before
var harness = new ServiceCollection()
.AddMassTransitInMemoryTestHarness()
.BuildServiceProvider();
var testHarness = harness.GetRequiredService<InMemoryTestHarness>(); // throws
// after
var harness = new ServiceCollection()
.AddMassTransit(x =>
{
x.AddConsumer<OrderConsumer>();
x.UsingInMemory((context, cfg) => cfg.ConfigureEndpoints(context));
x.AddConfigureEndpointsCallback((name, cfg) => cfg.UseInMemoryOutbox(context));
})
.AddMassTransitInMemoryTestHarness()
.BuildServiceProvider();
var testHarness = harness.GetRequiredService<InMemoryTestHarness>(); Defensive patterns
Strategy: try-catch
Validate before calling
var hasBusInstance = provider.GetService<IEnumerable<IBusInstance>>() != null || provider.GetService<IBusInstance>() != null;
if (!hasBusInstance)
throw new InvalidOperationException("No IBusInstance registered; configure the bus before resolving the test harness."); Type guard
bool HasBusInstance(IServiceProvider p) =>
p.GetService<IEnumerable<IBusInstance>>() is { } list && list.Any()
|| p.GetService<IBusInstance>() != null; Try / catch
try { var harness = provider.GetRequiredService<InMemoryTestHarness>(); }
catch (ConfigurationException ex)
{
// log: bus not configured; re-check AddMassTransit + harness registration
} Prevention
- Always pair AddMassTransitInMemoryTestHarness with a full AddMassTransit(x => x.UsingInMemory(...)) registration on the same IServiceCollection.
- Resolve the harness only from the built provider of that service collection, never a fresh container.
- Keep MassTransit core and testing package versions in lockstep.
When it happens
Trigger: Calling provider.GetRequiredService<InMemoryTestHarness>() (or BusTestHarness) from a container where AddMassTransitInMemoryTestHarness ran but no bus was ever registered - e.g. the test harness extension was added without a corresponding bus registration, or the harness is resolved from a different/wrong IServiceProvider than the one the bus was configured in.
Common situations: Unit test projects where the harness registration is combined with a container setup that strips or replaces IBusInstance registrations; resolving the harness before the bus configuration completes; using a custom container builder that does not flow IBusInstance; mixing MassTransit versions where the testing package and core package diverge.
Understand the failure class
Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.
Related errors
- Test Harness configuration is invalid
- The bus registration context cannot be null (via AddConfigur
- AddMassTransit() was already called and may only be called o
- Value cannot be null. (Parameter 'configure')
- Endpoints are not aligned on ConfigureConsumeTopology: {stri
AI-assisted analysis of MassTransit/MassTransit@62ab339afa (2026-09-13).
Data as JSON: /api/errors/615df4fb04adc26a.
Report an issue: GitHub.
Appendix: source
Thrown at src/MassTransit/Configuration/DependencyInjection/DependencyInjectionTestingExtensions.cs:244
/// </summary>
[Obsolete("Use AddMassTransitTestHarness instead. Visit https://masstransit.io/obsolete for details.")]
public static IServiceCollection AddMassTransitInMemoryTestHarness(this IServiceCollection services,
Action<IBusRegistrationConfigurator>? configure = null)
{
services.AddMassTransit(cfg =>
{
configure?.Invoke(cfg);
cfg.SetBusFactory(new InMemoryTestHarnessRegistrationBusFactory());
});
services.AddSingleton(provider =>
{
var busInstances = provider.GetService<IEnumerable<IBusInstance>>();
if (busInstances == null)
{
var busInstance = provider.GetService<IBusInstance>();
if (busInstance == null)
throw new ConfigurationException("No bus instances found");
busInstances = [busInstance];
}
var testHarnessBusInstance = busInstances.FirstOrDefault(x => x is InMemoryTestHarnessBusInstance);
if (testHarnessBusInstance is InMemoryTestHarnessBusInstance testInstance)
return testInstance.Harness;
throw new ConfigurationException("Test Harness configuration is invalid");
});
services.AddSingleton<BusTestHarness>(provider => provider.GetRequiredService<InMemoryTestHarness>());
return services;
}
static (string? methodName, string? className) GetTestMethodInfo()
{
var stackTrace = new StackTrace(2);View on GitHub (pinned to 62ab339afa)