{"record":{"id":"ee13e2add25e8d54","repo":"microsoft/aspire","slug":"a-typeof-tclient-name-could-not-be-configured-ensure-a-valid","errorCode":null,"errorMessage":"A {typeof(TClient).Name} could not be configured. Ensure a valid EventHubName was provided in the '{configurationSectionName}' configuration section, or include an EntityPath in the ConnectionString.","messagePattern":"A (.+?) could not be configured\\. Ensure a valid EventHubName was provided in the '(.+?)' configuration section, or include an EntityPath in the ConnectionString\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Aspire.Azure.Messaging.EventHubs/EventHubsComponent.cs","lineNumber":143,"sourceCode":"        {\n            throw new InvalidOperationException(\n                $\"A {typeof(TClient).Name} could not be configured. Ensure valid connection information was provided in \" +\n                $\"'ConnectionStrings:{connectionName}' or specify a 'ConnectionString' or 'FullyQualifiedNamespace' in the '{configurationSectionName}' configuration section.\");\n        }\n\n        // If we have a connection string, ensure there's an EntityPath if settings.EventHubName is missing\n        if (!string.IsNullOrWhiteSpace(settings.ConnectionString))\n        {\n            // We have a connection string -- do we have an EventHubName?\n            if (string.IsNullOrWhiteSpace(settings.EventHubName))\n            {\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":125,"sourceCodeEnd":160,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Components/Aspire.Azure.Messaging.EventHubs/EventHubsComponent.cs#L125-L160","documentation":"When a connection string is supplied but no EventHubName in settings, the component parses the connection string looking for an EntityPath that names the hub. If the EntityPath is also absent, Aspire cannot determine which event hub to use and throws.","triggerScenarios":"AddAzureEventHub* (via EnsureConnectionStringOrNamespaceProvided) with settings.EventHubName null/empty and a namespace-level connection string without 'EntityPath=<hub>' (EventHubsConnectionStringProperties.Parse returns empty EventHubName).","commonSituations":"Copying the Event Hubs namespace-level connection string (from the namespace SharedAccessPolicy) which lacks EntityPath, then forgetting to set EventHubName; typos in the settings callback so EventHubName isn't actually assigned; config key for EventHubName misspelled.","solutions":["Set settings.EventHubName in the settings callback or the '{configurationSectionName}:EventHubName' config key.","Or use an entity-scoped connection string that includes 'EntityPath=<hub-name>'.","Confirm the EventHubName config key is read (section name matches) if relying on configuration rather than code."],"exampleFix":"// before\nbuilder.AddAzureEventHubProducerClient(\"eh\"); // connection string has no EntityPath\n// after\nbuilder.AddAzureEventHubProducerClient(\"eh\", settings => { settings.EventHubName = \"orders\"; });\n// or use connection string with ;EntityPath=orders","handlingStrategy":"validation","validationCode":"var hubName = builder.Configuration[\"EventHubs:EventHubName\"];\nvar cs = builder.Configuration[\"ConnectionStrings:eh\"];\nvar hasEntityPath = cs?.Contains(\"EntityPath=\") == true;\nif (string.IsNullOrEmpty(hubName) && !hasEntityPath)\n    throw new InvalidOperationException(\"Set EventHubName or use a connection string with EntityPath.\");","typeGuard":null,"tryCatchPattern":"try { client = serviceProvider.GetRequiredService<EventHubProducerClient>(); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"EventHubName\")) { logger.LogError(ex, \"Event hub name missing\"); throw; }","preventionTips":["Always set EventHubName explicitly in the settings callback","Prefer namespace-level connection string + explicit EventHubName over EntityPath strings","Document required config keys for each environment"],"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"}