{"record":{"id":"d46dde529f4ed95a","repo":"microsoft/aspire","slug":"at-least-one-partition-key-path-should-be-provided","errorCode":null,"errorMessage":"At least one partition key path should be provided.","messagePattern":"At least one partition key path should be provided\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.CosmosDB/AzureCosmosDBContainerResource.cs","lineNumber":35,"sourceCode":"/// </remarks>\n[DebuggerDisplay(\"Type = {GetType().Name,nq}, Name = {Name}, Container = {ContainerName}\")]\npublic class AzureCosmosDBContainerResource : Resource, IResourceWithParent<AzureCosmosDBDatabaseResource>, IResourceWithConnectionString, IResourceWithAzureFunctionsConfig\n{\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"AzureCosmosDBContainerResource\"/> class.\n    /// </summary>\n    /// <param name=\"name\">The resource name.</param>\n    /// <param name=\"containerName\">The container name.</param>\n    /// <param name=\"partitionKeyPaths\">The hierarchical partition key paths.</param>\n    /// <param name=\"parent\">The parent Azure Cosmos DB database resource.</param>\n    public AzureCosmosDBContainerResource(string name, string containerName, IEnumerable<string> partitionKeyPaths, AzureCosmosDBDatabaseResource parent) : base(name)\n    {\n        ArgumentException.ThrowIfNullOrEmpty(containerName);\n        ArgumentNullException.ThrowIfNull(partitionKeyPaths);\n        var partitionKeyPathsArray = partitionKeyPaths.ToArray();\n        if (partitionKeyPathsArray.Length == 0)\n        {\n            throw new ArgumentException(\"At least one partition key path should be provided.\", nameof(partitionKeyPaths));\n        }\n        if (partitionKeyPaths.Any(string.IsNullOrEmpty))\n        {\n            throw new ArgumentException(\"Partition key paths cannot contain null or empty strings.\", nameof(partitionKeyPaths));\n        }\n        ContainerProperties = new ContainerProperties(containerName, partitionKeyPathsArray);\n\n        Parent = parent ?? throw new ArgumentNullException(nameof(parent));\n    }\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"AzureCosmosDBContainerResource\"/> class.\n    /// </summary>\n    /// <param name=\"name\">The resource name.</param>\n    /// <param name=\"containerName\">The container name.</param>\n    /// <param name=\"partitionKeyPath\">The partition key path.</param>\n    /// <param name=\"parent\">The parent Azure Cosmos DB database resource.</param>\n    public AzureCosmosDBContainerResource(string name, string containerName, string partitionKeyPath, AzureCosmosDBDatabaseResource parent) : base(name)","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.CosmosDB/AzureCosmosDBContainerResource.cs#L17-L53","documentation":"AzureCosmosDBContainerResource models a Cosmos DB container whose partition key can be composed of multiple paths (hierarchical partition keys). The constructor validates that at least one path is supplied; an empty collection cannot form a valid ContainerProperties partition key definition, so ArgumentException is thrown.","triggerScenarios":"Calling the constructor (or the AddContainer/AddModel API that routes to it) with an empty IEnumerable<string> for partitionKeyPaths, e.g. new AzureCosmosDBContainerResource(name, containerName, [], db) or AddContainer(..., []) where the collection was built dynamically and ended up empty.","commonSituations":"Building partition key paths from configuration and the config section is missing/empty; collecting paths from a hierarchy definition list that was never populated; passing a conditionally-filled list where all conditions were false.","solutions":["Supply at least one partition key path, e.g. new[] { \"/partitionKey\" }.","Validate the source collection's Count > 0 before constructing the resource and fail fast with a clear app-level error.","If partition keys come from configuration, provide a default or throw your own descriptive error when the config list is empty."],"exampleFix":"// before\nAddContainer(db, \"orders\", myPaths); // myPaths == []\n// after\nvar myPaths = new[] { \"/customerId\" };\nAddContainer(db, \"orders\", myPaths);","handlingStrategy":"validation","validationCode":"if (paths is null || paths.Count() == 0)\n{\n    throw new ArgumentException(\"Provide at least one partition key path, e.g. '/id'.\", nameof(paths));\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    AddContainer(db, \"orders\", paths);\n}\ncatch (ArgumentException ex) when (ex.ParamName == \"partitionKeyPaths\")\n{\n    logger.LogError(ex, \"Partition key path list was empty for container {Container}.\", containerName);\n    throw;\n}","preventionTips":["Never pass default-empty collections from configuration; require at least '/id'.","Validate dynamically built path lists before calling the constructor.","Prefer the fluent AddContainer API with explicit path arguments."],"tags":["argument-validation","cosmosdb","azure","empty-collection"],"backgroundTag":"empty-required-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"}