{"record":{"id":"3ecb099fd3c0dbd2","repo":"microsoft/aspire","slug":"count-must-be-between-1-and-250","errorCode":null,"errorMessage":"Count must be between 1 and 250.","messagePattern":"Count must be between 1 and 250\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.CosmosDB/AzureCosmosDBExtensions.cs","lineNumber":330,"sourceCode":"    /// <param name=\"builder\">Builder for the Cosmos emulator container</param>\n    /// <param name=\"count\">Desired partition count.</param>\n    /// <returns>Cosmos emulator resource builder.</returns>\n    /// <remarks>Not calling this method will result in the default of 10 partitions. The actual started partitions is always one more than specified.\n    /// See <a href=\"https://learn.microsoft.com/azure/cosmos-db/emulator-windows-arguments#change-the-number-of-default-containers\">this documentation</a> about setting the partition count.\n    /// </remarks>\n    [AspireExport]\n    public static IResourceBuilder<AzureCosmosDBEmulatorResource> WithPartitionCount(this IResourceBuilder<AzureCosmosDBEmulatorResource> builder, int count)\n    {\n        ArgumentNullException.ThrowIfNull(builder);\n\n        if (builder.Resource.InnerResource.IsVNextEmulator)\n        {\n            throw new NotSupportedException($\"'{nameof(WithPartitionCount)}' does not work when using the Linux-based (vNext) Azure Cosmos DB emulator.\");\n        }\n\n        if (count < 1 || count > 250)\n        {\n            throw new ArgumentOutOfRangeException(nameof(count), count, \"Count must be between 1 and 250.\");\n        }\n\n        return builder.WithEnvironment(\"AZURE_COSMOS_EMULATOR_PARTITION_COUNT\", count.ToString(CultureInfo.InvariantCulture));\n    }\n\n    /// <summary>\n    /// Adds a database to the associated Cosmos DB account resource.\n    /// </summary>\n    /// <param name=\"builder\">AzureCosmosDB resource builder.</param>\n    /// <param name=\"databaseName\">Name of database.</param>\n    /// <returns>A reference to the <see cref=\"IResourceBuilder{T}\"/>.</returns>\n    /// <remarks>This method is not available in polyglot app hosts. Use <see cref=\"AddCosmosDatabase\"/> instead.</remarks>\n    [AspireExportIgnore(Reason = \"Obsolete API with incorrect return type. Use AddCosmosDatabase instead.\")]\n    [Obsolete($\"This method is obsolete because it has the wrong return type and will be removed in a future version. Use {nameof(AddCosmosDatabase)} instead to add a Cosmos DB database.\")]\n    public static IResourceBuilder<AzureCosmosDBResource> AddDatabase(this IResourceBuilder<AzureCosmosDBResource> builder, string databaseName)\n    {\n        ArgumentNullException.ThrowIfNull(builder);\n        ArgumentException.ThrowIfNullOrEmpty(databaseName);","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.CosmosDB/AzureCosmosDBExtensions.cs#L312-L348","documentation":"WithPartitionCount validates that the emulator partition count is between 1 and 250 inclusive; values outside that range throw ArgumentOutOfRangeException including the offending value. The limit reflects the classic Azure Cosmos DB emulator's maximum supported partition count.","triggerScenarios":"Calling WithPartitionCount(0), WithPartitionCount(-1), or WithPartitionCount(251) and above.","commonSituations":"Reading the count from configuration where a default of 0 is used; attempting large values for load testing beyond emulator limits.","solutions":["Pass a value between 1 and 250.","Clamp or validate configuration-derived values before calling the API.","Reduce the desired partition count to the emulator-supported maximum of 250."],"exampleFix":"// before\nvar count = int.Parse(config[\"PartitionCount\"]); // \"0\"\ncosmos.WithPartitionCount(count);\n// after\nvar count = Math.Clamp(int.Parse(config[\"PartitionCount\"] ?? \"10\"), 1, 250);\ncosmos.WithPartitionCount(count);","handlingStrategy":"validation","validationCode":"if (count is < 1 or > 250) throw new ArgumentOutOfRangeException(nameof(count));","typeGuard":null,"tryCatchPattern":"try { builder.WithPartitionCount(count); } catch (ArgumentOutOfRangeException) { /* clamp to 1..250 and retry */ }","preventionTips":["Clamp config-derived counts with Math.Clamp(value, 1, 250).","Never pass 0 or negatives from defaults.","Remember the emulator caps at 250 partitions."],"tags":["cosmosdb","emulator","argument-out-of-range"],"backgroundTag":"value-out-of-range","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"}