{"record":{"id":"11a8d9d27c3cba0c","repo":"microsoft/aspire","slug":"a-partitionreceiver-could-not-be-configured-ensure-a-valid","errorCode":null,"errorMessage":"A PartitionReceiver could not be configured. Ensure a valid PartitionId was provided in the '{configurationSectionName}' configuration section.","messagePattern":"A PartitionReceiver could not be configured\\. Ensure a valid PartitionId was provided in the '(.+?)' configuration section\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Aspire.Azure.Messaging.EventHubs/PartitionReceiverClientComponent.cs","lineNumber":40,"sourceCode":"    }\n\n    protected override void BindSettingsToConfiguration(AzureMessagingEventHubsPartitionReceiverSettings settings, IConfiguration config)\n    {\n        config.Bind(settings);\n    }\n\n    protected override IAzureClientBuilder<PartitionReceiver, PartitionReceiverOptions> AddClient(\n        AzureClientFactoryBuilder azureFactoryBuilder, AzureMessagingEventHubsPartitionReceiverSettings settings,\n        string connectionName, string configurationSectionName)\n    {\n        return ((IAzureClientFactoryBuilderWithCredential)azureFactoryBuilder).RegisterClientFactory<PartitionReceiver, PartitionReceiverOptions>((options, cred) =>\n        {\n            // ensure that the connection string or namespace+eventhubname is provided\n            EnsureConnectionStringOrNamespaceProvided(settings, connectionName, configurationSectionName);\n\n            if (string.IsNullOrEmpty(settings.PartitionId))\n            {\n                throw new InvalidOperationException(\n                    $\"A PartitionReceiver could not be configured. Ensure a valid PartitionId was provided in the '{configurationSectionName}' configuration section.\");\n            }\n\n            options.Identifier ??= GenerateClientIdentifier(settings.EventHubName, settings.ConsumerGroup);\n\n            if (string.IsNullOrEmpty(settings.ConnectionString))\n            {\n                return new PartitionReceiver(\n                    settings.ConsumerGroup ?? EventHubConsumerClient.DefaultConsumerGroupName,\n                    settings.PartitionId,\n                    settings.EventPosition,\n                    settings.FullyQualifiedNamespace,\n                    settings.EventHubName,\n                    cred, options);\n            }\n\n            if (string.IsNullOrEmpty(settings.EventHubName))\n            {","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Components/Aspire.Azure.Messaging.EventHubs/PartitionReceiverClientComponent.cs#L22-L58","documentation":"PartitionReceiverClientComponent builds a PartitionReceiver, which by definition must target a specific Event Hub partition. After validating connection/namespace info, AddClient checks settings.PartitionId and throws if it's empty, since a PartitionReceiver cannot be created without it.","triggerScenarios":"AddAzurePartitionReceiverClient (AddClient) when settings.PartitionId is null/empty — PartitionId absent from both the settings callback and the '{configurationSectionName}' configuration section.","commonSituations":"Developer uses the partition receiver component but forgets that unlike regular consumers, a partition id is mandatory; copying the setup for AddAzureEventHubConsumerClient (which doesn't need PartitionId); config key 'PartitionId' missing from appsettings.json; intending dynamic partition assignment when PartitionReceiver is the wrong API.","solutions":["Set settings.PartitionId in the ConfigureSettings callback, e.g. settings => settings.PartitionId = \"0\".","Or add '\"PartitionId\": \"0\"' under the '{configurationSectionName}' config section.","If you don't actually need a fixed partition, use AddAzureEventHubConsumerClient (EventProcessorClient/EventHubConsumerClient) instead of the PartitionReceiver component."],"exampleFix":"// before\nbuilder.AddAzurePartitionReceiverClient(\"eh\", settings => { settings.EventHubName = \"orders\"; }); // missing PartitionId\n// after\nbuilder.AddAzurePartitionReceiverClient(\"eh\", settings => { settings.EventHubName = \"orders\"; settings.PartitionId = \"0\"; });","handlingStrategy":"validation","validationCode":"var partitionId = builder.Configuration[\"PartitionReceiver:PartitionId\"];\nif (string.IsNullOrEmpty(partitionId) || !int.TryParse(partitionId, out _))\n    throw new InvalidOperationException(\"PartitionId must be set (e.g. \\\"0\\\") before AddAzurePartitionReceiverClient.\");","typeGuard":null,"tryCatchPattern":"try { receiver = serviceProvider.GetRequiredService<PartitionReceiver>(); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"PartitionId\")) { logger.LogError(ex, \"PartitionId missing for PartitionReceiver\"); throw; }","preventionTips":["Set PartitionId explicitly in the settings callback at registration","If partitions are dynamic, use the EventHubConsumerClient/EventProcessorClient components instead","Validate partition ids exist on the hub (GetEventHubProperties) at startup"],"tags":["azure","event-hubs","configuration","partition-receiver"],"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"}