{"record":{"id":"e83edcf58d618311","repo":"microsoft/aspire","slug":"a-typeof-tclient-name-could-not-be-configured-please-ensure","errorCode":null,"errorMessage":"A {typeof(TClient).Name} could not be configured. Please ensure that the ConnectionString or FullyQualifiedNamespace is well-formed.","messagePattern":"A (.+?) could not be configured\\. Please ensure that the ConnectionString or FullyQualifiedNamespace is well-formed\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Aspire.Azure.Messaging.EventHubs/EventHubsComponent.cs","lineNumber":111,"sourceCode":"            ns = string.IsNullOrWhiteSpace(settings.FullyQualifiedNamespace)\n                ? EventHubsConnectionStringProperties.Parse(settings.ConnectionString).Endpoint.Host\n                : new Uri(settings.FullyQualifiedNamespace).Host;\n\n            // This is likely to be similar to {yournamespace}.servicebus.windows.net or {yournamespace}.servicebus.chinacloudapi.cn\n            var serviceBusIndex = ns.IndexOf(\".servicebus\", StringComparison.OrdinalIgnoreCase);\n            if (serviceBusIndex != -1)\n            {\n                ns = ns[..serviceBusIndex];\n            }\n            else\n            {\n                // sanitize the namespace if it's not a servicebus namespace\n                ns = ns.Replace(\".\", \"-\");\n            }\n        }\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        }","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Components/Aspire.Azure.Messaging.EventHubs/EventHubsComponent.cs#L93-L129","documentation":"EventHubsComponent sanitizes an Event Hubs namespace (derived from the connection string or FullyQualifiedNamespace) for use in names such as blob container/consumer identifiers. If parsing the connection string or namespace throws FormatException or IndexOutOfRangeException, the value is malformed and the component rethrows as an InvalidOperationException naming the client type.","triggerScenarios":"GetNamespaceFromSettings throws when the ConnectionString is not a well-formed Event Hubs connection string (e.g. missing 'Endpoint=sb://...' part causing parsing errors) or FullyQualifiedNamespace is malformed, during any AddAzureEventHub* client registration.","commonSituations":"Connection string copied incorrectly (truncated, quotes included, wrong service's connection string such as a Storage or ServiceBus string); whitespace or invalid characters in FullyQualifiedNamespace; hand-edited config missing required segments.","solutions":["Copy the full Event Hubs connection string from the portal (SharedAccessPolicy connection string, format: Endpoint=sb://<ns>.servicebus.windows.net/;SharedAccessKeyName=...;SharedAccessKey=...).","If using FullyQualifiedNamespace instead, set it to '<namespace>.servicebus.windows.net' with no scheme or path.","Validate the connection string by constructing EventHubsConnectionStringProperties.Parse(connectionString) locally to see the exact parse failure.","Check for accidental inclusion of surrounding quotes or extra semicolons in configuration."],"exampleFix":"// before\n// ConnectionStrings:events = \"sb://myns.servicebus.windows.net/\"  (not a valid connection string)\n// after\n// ConnectionStrings:events = \"Endpoint=sb://myns.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=...\"\nbuilder.AddAzureEventHubProducerClient(\"events\", \"hub\");","handlingStrategy":"validation","validationCode":"var cs = builder.Configuration[\"ConnectionStrings:eh\"];\nif (!string.IsNullOrEmpty(cs))\n{\n    try { var p = Azure.Messaging.EventHubs.EventHubsConnectionStringProperties.Parse(cs); _ = p.FullyQualifiedNamespace; }\n    catch (Exception ex) { throw new InvalidOperationException($\"Malformed Event Hubs connection string: {ex.Message}\"); }\n}","typeGuard":null,"tryCatchPattern":"try { return serviceProvider.GetRequiredService<EventHubProducerClient>(); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"well-formed\")) { logger.LogError(ex, \"Event Hubs connection string format is invalid\"); throw; }","preventionTips":["Always copy the connection string directly from the portal without manual edits","Parse with EventHubsConnectionStringProperties in a startup health check","Prefer FullyQualifiedNamespace + credential to avoid connection-string parsing entirely","Watch for quotes/whitespace sneaking into config values from secret managers"],"tags":["azure","event-hubs","connection-string","format"],"backgroundTag":"invalid-argument-format","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}