{"record":{"id":"e8d07647c1cd2340","repo":"microsoft/aspire","slug":"a-typeof-tclient-name-could-not-be-configured-ensure-a-valid-e8d076","errorCode":null,"errorMessage":"A {typeof(TClient).Name} could not be configured. Ensure a valid EventHubName was provided in the '{configurationSectionName}' configuration section.","messagePattern":"A (.+?) could not be configured\\. Ensure a valid EventHubName was provided in the '(.+?)' configuration section\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Aspire.Azure.Messaging.EventHubs/EventHubsComponent.cs","lineNumber":154,"sourceCode":"            {\n                // look for EntityPath\n                var props = EventHubsConnectionStringProperties.Parse(connectionString);\n\n                // if EntityPath is missing, throw\n                if (string.IsNullOrWhiteSpace(props.EventHubName))\n                {\n                    throw new InvalidOperationException(\n                        $\"A {typeof(TClient).Name} could not be configured. Ensure a valid EventHubName was provided in \" +\n                        $\"the '{configurationSectionName}' configuration section, or include an EntityPath in the ConnectionString.\");\n                }\n                // The connection string has an EventHubName, but we'll set this anyway so the health check can use it\n                settings.EventHubName = props.EventHubName;\n            }\n        }\n        // If we have a namespace and no connection string, ensure there's an EventHubName\n        else if (!string.IsNullOrWhiteSpace(settings.FullyQualifiedNamespace) && string.IsNullOrWhiteSpace(settings.EventHubName))\n        {\n            throw new InvalidOperationException(\n                $\"A {typeof(TClient).Name} could not be configured. Ensure a valid EventHubName was provided in \" +\n                $\"the '{configurationSectionName}' configuration section.\");\n        }\n    }\n}\n","sourceCodeStart":136,"sourceCodeEnd":160,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Components/Aspire.Azure.Messaging.EventHubs/EventHubsComponent.cs#L136-L160","documentation":"When FullyQualifiedNamespace is provided (no connection string), the event hub name must come from settings because a namespace alone doesn't identify a hub. If EventHubName is null/empty in that scenario, the component throws.","triggerScenarios":"AddAzureEventHub* (EnsureConnectionStringOrNamespaceProvided) when settings.ConnectionString is empty, settings.FullyQualifiedNamespace is set, and settings.EventHubName is null/whitespace.","commonSituations":"Using Microsoft Entra ID authentication with only the namespace configured but forgetting to set EventHubName; '{configurationSectionName}:EventHubName' missing from appsettings.json; settings callback assigning EventHubName conditionally and the condition not firing.","solutions":["Set settings.EventHubName in the ConfigureSettings callback.","Or add '\"EventHubName\": \"<hub>\"' under the '{configurationSectionName}' config section.","Alternatively supply a full connection string containing EntityPath instead of FullyQualifiedNamespace."],"exampleFix":"// before\nbuilder.AddAzureEventHubConsumerClient(\"eh\", settings => { settings.FullyQualifiedNamespace = \"ns.servicebus.windows.net\"; });\n// after\nbuilder.AddAzureEventHubConsumerClient(\"eh\", settings => {\n  settings.FullyQualifiedNamespace = \"ns.servicebus.windows.net\";\n  settings.EventHubName = \"orders\";\n});","handlingStrategy":"validation","validationCode":"var cs = builder.Configuration[\"ConnectionStrings:eh\"];\nvar hubName = builder.Configuration[\"EventHubs:EventHubName\"];\nif (string.IsNullOrEmpty(cs) && string.IsNullOrEmpty(hubName))\n    throw new InvalidOperationException(\"Namespace-only configuration requires EventHubName.\");","typeGuard":null,"tryCatchPattern":"try { consumer = serviceProvider.GetRequiredService<EventHubConsumerClient>(); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"EventHubName\")) { logger.LogError(ex, \"EventHubName required when using FullyQualifiedNamespace\"); throw; }","preventionTips":["When using Entra ID/namespace auth, always pair it with EventHubName in settings","Add EventHubName to your configuration template for all environments","Write an options-validation (IValidateOptions) check for the EventHubs settings section"],"tags":["azure","event-hubs","configuration","event-hub-name"],"backgroundTag":"missing-required-config-field","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}