{"record":{"id":"8cdb814a29be9635","repo":"microsoft/aspire","slug":"a-typeof-tclient-name-could-not-be-configured-ensure-valid","errorCode":null,"errorMessage":"A {typeof(TClient).Name} could not be configured. Ensure valid connection information was provided in 'ConnectionStrings:{connectionName}' or specify a 'ConnectionString' or 'FullyQualifiedNamespace' in the '{configurationSectionName}' configuration section.","messagePattern":"A (.+?) could not be configured\\. Ensure valid connection information was provided in 'ConnectionStrings:(.+?)' or specify a 'ConnectionString' or 'FullyQualifiedNamespace' in the '(.+?)' configuration section\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Aspire.Azure.Messaging.EventHubs/EventHubsComponent.cs","lineNumber":126,"sourceCode":"        }\n        catch (Exception ex) when (ex is FormatException or IndexOutOfRangeException)\n        {\n            throw new InvalidOperationException(\n                $\"A {typeof(TClient).Name} could not be configured. Please ensure that the ConnectionString or FullyQualifiedNamespace is well-formed.\");\n        }\n\n        return ns;\n    }\n\n    protected static void EnsureConnectionStringOrNamespaceProvided(AzureMessagingEventHubsSettings settings,\n        string connectionName, string configurationSectionName)\n    {\n        var connectionString = settings.ConnectionString;\n\n        // Are we missing both connection string and namespace? throw.\n        if (string.IsNullOrEmpty(connectionString) && string.IsNullOrEmpty(settings.FullyQualifiedNamespace))\n        {\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 \" +","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Components/Aspire.Azure.Messaging.EventHubs/EventHubsComponent.cs#L108-L144","documentation":"EnsureConnectionStringOrNamespaceProvided requires that at least one of ConnectionString or FullyQualifiedNamespace is present in the bound EventHubs settings. When both are missing there is no endpoint to connect to, so the component throws before creating the client factory registration.","triggerScenarios":"Calling AddAzureEventHubProducerClient/ConsumerClient/EventHubClient (AddClient path invoking EnsureConnectionStringOrNamespaceProvided) when settings.ConnectionString is null/empty and settings.FullyQualifiedNamespace is null/empty.","commonSituations":"No 'ConnectionStrings:{connectionName}' key in configuration; config section '{configurationSectionName}:FullyQualifiedNamespace' not set; running outside the Aspire AppHost so the connection string was never injected; key name mismatch between the AddAzure... call and config.","solutions":["Add the Event Hubs connection string under 'ConnectionStrings:{connectionName}' in appsettings.json or as environment variable ConnectionStrings__<name>.","Or set FullyQualifiedNamespace in the '{configurationSectionName}' section (plus a credential) instead of a connection string.","If using Aspire, add .WithReference(eventHubs) in the AppHost so the connection string is injected automatically.","Verify the connectionName/configurationSectionName arguments match your configuration keys."],"exampleFix":"// before\nbuilder.AddAzureEventHubProducerClient(\"eh\", settings => { settings.EventHubName = \"hub\"; }); // no connection info\n// after (appsettings.json)\n// { \"ConnectionStrings\": { \"eh\": \"Endpoint=sb://ns.servicebus.windows.net/;...\" } }\nbuilder.AddAzureEventHubProducerClient(\"eh\", settings => { settings.EventHubName = \"hub\"; });","handlingStrategy":"validation","validationCode":"var section = builder.Configuration.GetSection(\"ConnectionStrings:eh\");\nvar fqns = builder.Configuration[\"EventHubs:FullyQualifiedNamespace\"];\nif (string.IsNullOrEmpty(section.Value) && string.IsNullOrEmpty(fqns))\n    throw new InvalidOperationException(\"Configure ConnectionStrings:eh or EventHubs:FullyQualifiedNamespace before AddAzureEventHub*.\");","typeGuard":"bool hasEventHubsConnection = !string.IsNullOrWhiteSpace(config[\"ConnectionStrings:eh\"]) || !string.IsNullOrWhiteSpace(config[\"EventHubs:FullyQualifiedNamespace\"]);","tryCatchPattern":"try { hubClient = serviceProvider.GetRequiredService<EventHubProducerClient>(); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"could not be configured\")) { logger.LogCritical(ex, \"Event Hubs connection info missing\"); throw; }","preventionTips":["Use WithReference in the AppHost to inject connection strings automatically","Assert required config keys at startup (fail fast before serving traffic)","Match configuration section names exactly with the component registration names"],"tags":["azure","event-hubs","configuration","connection-string"],"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"}