MassTransit/MassTransit · error · ConfigurationException

The hostConfiguration was not properly configured for Azure

Error message

The hostConfiguration was not properly configured for Azure Service Bus

What it means

EventReceiver requires the bus instance's HostConfiguration to implement IServiceBusHostConfiguration (the Azure Service Bus host configuration contract). If the running bus was configured with a different transport's host configuration, the cast fails and MassTransit throws this ConfigurationException. It guards against mixing the EventHubs functions integration with a non-ServiceBus configured bus.

Solutions

  1. Configure the bus with Azure Service Bus: call x.UsingServiceBus((context, cfg) => ...) in AddMassTransit configuration.
  2. Ensure the ServiceBus connection (ServiceBusConnection connection string or fullyQualifiedNamespace) is set so the ServiceBus host configuration is created.
  3. Check that you are using the matching MassTransit.WebJobs integration package version and registering via AddMassTransitForAzureFunctions.
  4. Remove conflicting transport configurations (e.g. UsingRabbitMq) so the Service Bus host configuration is the active one.

Example fix

// before
services.AddMassTransit(x => { x.AddConsumer<MyConsumer>(); }); // in-memory bus
// after
services.AddMassTransit(x =>
{
    x.AddConsumer<MyConsumer>();
    x.UsingServiceBus((context, cfg) =>
    {
        cfg.Host("<connection-string>");
        cfg.ConfigureEndpoints(context);
    });
});
Defensive patterns

Strategy: validation

Validate before calling

// ensure Service Bus transport is configured before startup
var sbConn = Environment.GetEnvironmentVariable("ServiceBusConnection");
if (string.IsNullOrWhiteSpace(sbConn))
    throw new InvalidOperationException("ServiceBusConnection must be set; the EventHubs functions integration requires an Azure Service Bus-configured bus");

Type guard

bool IsServiceBusHost(IBusInstance instance) => instance.HostConfiguration is IServiceBusHostConfiguration;

Try / catch

try
{
    await eventReceiver.Handle(message, configure, cancellationToken);
}
catch (ConfigurationException ex) when (ex.Message.Contains("hostConfiguration"))
{
    logger.LogCritical(ex, "Bus is not configured for Azure Service Bus");
    throw;
}

Prevention

When it happens

Trigger: Constructing EventReceiver (during bus startup with the WebJobs EventHubs integration) when busInstance.HostConfiguration is not an IServiceBusHostConfiguration — e.g. the bus was registered without Azure Service Bus transport configuration, or with plain AddMassTransit without UseServiceBus.

Common situations: Using the EventHubs functions package alongside a bus configured only for in-memory or RabbitMQ transport; wrong DI registration order; hosting multiple bus instances where the resolved instance lacks Service Bus configuration.

Understand the failure class

Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.

Related errors


AI-assisted analysis of MassTransit/MassTransit@62ab339afa (2026-09-13). Data as JSON: /api/errors/ed117f00112c897b. Report an issue: GitHub.

Appendix: source

Thrown at src/Transports/MassTransit.WebJobs.EventHubsIntegration/EventHubIntegration/EventReceiver.cs:24

    using System.Threading.Tasks;
    using Azure.Messaging.EventHubs;
    using AzureServiceBusTransport.Configuration;
    using Configuration;
    using Transports;


    public class EventReceiver :
        IEventReceiver
    {
        readonly IAsyncBusHandle _busHandle;
        readonly IServiceBusHostConfiguration _hostConfiguration;
        readonly ConcurrentDictionary<string, IEventDataReceiver> _receivers;
        readonly IBusRegistrationContext _registration;

        public EventReceiver(IBusRegistrationContext registration, IAsyncBusHandle busHandle, IBusInstance busInstance)
        {
            _hostConfiguration = busInstance.HostConfiguration as IServiceBusHostConfiguration
                ?? throw new ConfigurationException("The hostConfiguration was not properly configured for Azure Service Bus");

            _registration = registration;
            _busHandle = busHandle;

            _receivers = new ConcurrentDictionary<string, IEventDataReceiver>();
        }

        public void Dispose()
        {
        }

        public Task Handle(string entityName, EventData message, CancellationToken cancellationToken)
        {
            var receiver = CreateEventDataReceiver(entityName, cfg =>
            {
                cfg.ConfigureConsumers(_registration);
                cfg.ConfigureSagas(_registration);
            });

View on GitHub (pinned to 62ab339afa)