microsoft/aspire · error · ArgumentException

At least one partition key path should be provided.

Error message

At least one partition key path should be provided.

What it means

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.

Solutions

  1. Supply at least one partition key path, e.g. new[] { "/partitionKey" }.
  2. Validate the source collection's Count > 0 before constructing the resource and fail fast with a clear app-level error.
  3. If partition keys come from configuration, provide a default or throw your own descriptive error when the config list is empty.

Example fix

// before
AddContainer(db, "orders", myPaths); // myPaths == []
// after
var myPaths = new[] { "/customerId" };
AddContainer(db, "orders", myPaths);
Defensive patterns

Strategy: validation

Validate before calling

if (paths is null || paths.Count() == 0)
{
    throw new ArgumentException("Provide at least one partition key path, e.g. '/id'.", nameof(paths));
}

Try / catch

try
{
    AddContainer(db, "orders", paths);
}
catch (ArgumentException ex) when (ex.ParamName == "partitionKeyPaths")
{
    logger.LogError(ex, "Partition key path list was empty for container {Container}.", containerName);
    throw;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/d46dde529f4ed95a. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.Azure.CosmosDB/AzureCosmosDBContainerResource.cs:35

/// </remarks>
[DebuggerDisplay("Type = {GetType().Name,nq}, Name = {Name}, Container = {ContainerName}")]
public class AzureCosmosDBContainerResource : Resource, IResourceWithParent<AzureCosmosDBDatabaseResource>, IResourceWithConnectionString, IResourceWithAzureFunctionsConfig
{
    /// <summary>
    /// Initializes a new instance of the <see cref="AzureCosmosDBContainerResource"/> class.
    /// </summary>
    /// <param name="name">The resource name.</param>
    /// <param name="containerName">The container name.</param>
    /// <param name="partitionKeyPaths">The hierarchical partition key paths.</param>
    /// <param name="parent">The parent Azure Cosmos DB database resource.</param>
    public AzureCosmosDBContainerResource(string name, string containerName, IEnumerable<string> partitionKeyPaths, AzureCosmosDBDatabaseResource parent) : base(name)
    {
        ArgumentException.ThrowIfNullOrEmpty(containerName);
        ArgumentNullException.ThrowIfNull(partitionKeyPaths);
        var partitionKeyPathsArray = partitionKeyPaths.ToArray();
        if (partitionKeyPathsArray.Length == 0)
        {
            throw new ArgumentException("At least one partition key path should be provided.", nameof(partitionKeyPaths));
        }
        if (partitionKeyPaths.Any(string.IsNullOrEmpty))
        {
            throw new ArgumentException("Partition key paths cannot contain null or empty strings.", nameof(partitionKeyPaths));
        }
        ContainerProperties = new ContainerProperties(containerName, partitionKeyPathsArray);

        Parent = parent ?? throw new ArgumentNullException(nameof(parent));
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="AzureCosmosDBContainerResource"/> class.
    /// </summary>
    /// <param name="name">The resource name.</param>
    /// <param name="containerName">The container name.</param>
    /// <param name="partitionKeyPath">The partition key path.</param>
    /// <param name="parent">The parent Azure Cosmos DB database resource.</param>
    public AzureCosmosDBContainerResource(string name, string containerName, string partitionKeyPath, AzureCosmosDBDatabaseResource parent) : base(name)

View on GitHub (pinned to 25830f84bd)