{"record":{"id":"430263cc8173afd1","repo":"microsoft/aspire","slug":"at-least-one-partition-key-path-should-be-provided-430263","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/AzureCosmosDBExtensions.cs","lineNumber":443,"sourceCode":"\n    /// <summary>\n    /// Adds a container to the associated Cosmos DB database resource with hierarchical partition keys.\n    /// </summary>\n    /// <param name=\"builder\">CosmosDBDatabase resource builder.</param>\n    /// <param name=\"name\">Name of container resource.</param>\n    /// <param name=\"partitionKeyPaths\">Hierarchical partition key paths for the container.</param>\n    /// <param name=\"containerName\">The name of the container. If not provided, this defaults to the same value as <paramref name=\"name\"/>.</param>\n    /// <returns>A reference to the <see cref=\"IResourceBuilder{T}\"/>.</returns>\n    [AspireExportIgnore(Reason = \"Polyglot AppHosts use the internal addContainer dispatcher export.\")]\n    public static IResourceBuilder<AzureCosmosDBContainerResource> AddContainer(this IResourceBuilder<AzureCosmosDBDatabaseResource> builder, [ResourceName] string name, IEnumerable<string> partitionKeyPaths, string? containerName = null)\n    {\n        ArgumentNullException.ThrowIfNull(builder);\n        ArgumentException.ThrowIfNullOrEmpty(name);\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\n        if (partitionKeyPathsArray.Any(string.IsNullOrEmpty))\n        {\n            throw new ArgumentException(\"Partition key paths cannot contain null or empty strings.\", nameof(partitionKeyPaths));\n        }\n\n        // Use the resource name as the container name if it's not provided\n        containerName ??= name;\n\n        var container = new AzureCosmosDBContainerResource(name, containerName, partitionKeyPaths, builder.Resource);\n\n        builder.Resource.Containers.Add(container);\n\n        return builder.ApplicationBuilder.AddResource(container)\n            .WithIconName(\"Box\");\n    }\n","sourceCodeStart":425,"sourceCodeEnd":461,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.CosmosDB/AzureCosmosDBExtensions.cs#L425-L461","documentation":"AddContainer requires at least one partition key path: the extension materializes the collection to an array and throws ArgumentException when it is empty, mirroring the resource-level validation. Cosmos DB containers cannot be defined without a partition key path.","triggerScenarios":"Calling builder.AddContainer(name, Array.Empty<string>()) or an empty List<string>; passing a lazily-evaluated enumerable that yields no items.","commonSituations":"Building the path list from config where no keys were configured; a LINQ filter that removes all entries before the call; default-initialized empty arrays.","solutions":["Pass at least one non-empty partition key path such as \"/id\".","Validate the collection is non-empty before calling AddContainer.","Fix the upstream configuration so at least one path is populated."],"exampleFix":"// before\nvar paths = config.GetPartitionKeyPaths(); // returns empty list\ndb.AddContainer(\"orders\", paths);\n// after\nvar paths = config.GetPartitionKeyPaths();\nif (paths.Count == 0) throw new InvalidOperationException(\"At least one partition key path must be configured.\");\ndb.AddContainer(\"orders\", paths);","handlingStrategy":"validation","validationCode":"if (partitionKeyPaths is null || !partitionKeyPaths.Any()) throw new ArgumentException(\"At least one partition key path must be provided.\");","typeGuard":null,"tryCatchPattern":"try { db.AddContainer(\"orders\", paths); } catch (ArgumentException ex) when (ex.ParamName == \"partitionKeyPaths\") { /* fall back to \"/id\" and retry */ }","preventionTips":["Default to \"/id\" when no path is configured.","Filter config-derived lists before calling, then check count.","Fail fast on empty collections at configuration load time."],"tags":["cosmosdb","partition-key","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"}