{"record":{"id":"ed117f00112c897b","repo":"MassTransit/MassTransit","slug":"the-hostconfiguration-was-not-properly-configured-for-azure-ed117f","errorCode":null,"errorMessage":"The hostConfiguration was not properly configured for Azure Service Bus","messagePattern":"The hostConfiguration was not properly configured for Azure Service Bus","errorType":"exception","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"src/Transports/MassTransit.WebJobs.EventHubsIntegration/EventHubIntegration/EventReceiver.cs","lineNumber":24,"sourceCode":"    using System.Threading.Tasks;\n    using Azure.Messaging.EventHubs;\n    using AzureServiceBusTransport.Configuration;\n    using Configuration;\n    using Transports;\n\n\n    public class EventReceiver :\n        IEventReceiver\n    {\n        readonly IAsyncBusHandle _busHandle;\n        readonly IServiceBusHostConfiguration _hostConfiguration;\n        readonly ConcurrentDictionary<string, IEventDataReceiver> _receivers;\n        readonly IBusRegistrationContext _registration;\n\n        public EventReceiver(IBusRegistrationContext registration, IAsyncBusHandle busHandle, IBusInstance busInstance)\n        {\n            _hostConfiguration = busInstance.HostConfiguration as IServiceBusHostConfiguration\n                ?? throw new ConfigurationException(\"The hostConfiguration was not properly configured for Azure Service Bus\");\n\n            _registration = registration;\n            _busHandle = busHandle;\n\n            _receivers = new ConcurrentDictionary<string, IEventDataReceiver>();\n        }\n\n        public void Dispose()\n        {\n        }\n\n        public Task Handle(string entityName, EventData message, CancellationToken cancellationToken)\n        {\n            var receiver = CreateEventDataReceiver(entityName, cfg =>\n            {\n                cfg.ConfigureConsumers(_registration);\n                cfg.ConfigureSagas(_registration);\n            });","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/MassTransit/MassTransit/blob/62ab339afa3bac2e9b3fe1769d0d35d7e44778e9/src/Transports/MassTransit.WebJobs.EventHubsIntegration/EventHubIntegration/EventReceiver.cs#L6-L42","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Configure the bus with Azure Service Bus: call x.UsingServiceBus((context, cfg) => ...) in AddMassTransit configuration.","Ensure the ServiceBus connection (ServiceBusConnection connection string or fullyQualifiedNamespace) is set so the ServiceBus host configuration is created.","Check that you are using the matching MassTransit.WebJobs integration package version and registering via AddMassTransitForAzureFunctions.","Remove conflicting transport configurations (e.g. UsingRabbitMq) so the Service Bus host configuration is the active one."],"exampleFix":"// before\nservices.AddMassTransit(x => { x.AddConsumer<MyConsumer>(); }); // in-memory bus\n// after\nservices.AddMassTransit(x =>\n{\n    x.AddConsumer<MyConsumer>();\n    x.UsingServiceBus((context, cfg) =>\n    {\n        cfg.Host(\"<connection-string>\");\n        cfg.ConfigureEndpoints(context);\n    });\n});","handlingStrategy":"validation","validationCode":"// ensure Service Bus transport is configured before startup\nvar sbConn = Environment.GetEnvironmentVariable(\"ServiceBusConnection\");\nif (string.IsNullOrWhiteSpace(sbConn))\n    throw new InvalidOperationException(\"ServiceBusConnection must be set; the EventHubs functions integration requires an Azure Service Bus-configured bus\");","typeGuard":"bool IsServiceBusHost(IBusInstance instance) => instance.HostConfiguration is IServiceBusHostConfiguration;","tryCatchPattern":"try\n{\n    await eventReceiver.Handle(message, configure, cancellationToken);\n}\ncatch (ConfigurationException ex) when (ex.Message.Contains(\"hostConfiguration\"))\n{\n    logger.LogCritical(ex, \"Bus is not configured for Azure Service Bus\");\n    throw;\n}","preventionTips":["Always call x.UsingServiceBus(...) in AddMassTransit when using the EventHubs functions package","Use AddMassTransitForAzureFunctions rather than manual EventReceiver construction","Add a startup smoke test that resolves the bus and asserts the host configuration type"],"tags":["masstransit","azure-servicebus","configuration","type-mismatch"],"backgroundTag":"missing-required-config","analyzedSha":"62ab339afa3bac2e9b3fe1769d0d35d7e44778e9","analyzedAt":"2026-09-13T22:47:47.593Z","contentChangedAt":"2026-09-13T22:47:47.593Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}