{"record":{"id":"207b6cb709c68a07","repo":"microsoft/aspire","slug":"withpartitioncount-does-not-work-when-using-the-linux-based","errorCode":null,"errorMessage":"'{WithPartitionCount}' does not work when using the Linux-based (vNext) Azure Cosmos DB emulator.","messagePattern":"'(.+?)' does not work when using the Linux-based \\(vNext\\) Azure Cosmos DB emulator\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.CosmosDB/AzureCosmosDBExtensions.cs","lineNumber":325,"sourceCode":"    }\n\n    /// <summary>\n    /// Configures the partition count for the Azure Cosmos DB emulator.\n    /// </summary>\n    /// <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.\")]","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.CosmosDB/AzureCosmosDBExtensions.cs#L307-L343","documentation":"WithPartitionCount configures the classic Windows emulator via the AZURE_COSMOS_EMULATOR_PARTITION_COUNT environment variable, but the Linux-based vNext emulator does not support this setting. Calling WithPartitionCount on a resource configured with RunAsVNextEmulator throws NotSupportedException by design.","triggerScenarios":"Calling RunAsVNextEmulator() followed by WithPartitionCount(n) on the same builder (IsVNextEmulator is true).","commonSituations":"Migrating an app host from the classic Windows emulator to the vNext Linux emulator while keeping existing emulator tuning calls in place.","solutions":["Remove the WithPartitionCount call when using RunAsVNextEmulator; the vNext emulator does not expose this knob.","Keep WithPartitionCount only for the classic emulator path (RunAsEmulator without vNext).","Check builder.Resource.InnerResource.IsVNextEmulator at runtime and apply the call conditionally."],"exampleFix":"// before\nbuilder.AddAzureCosmosDB(\"cosmos\").RunAsVNextEmulator().WithPartitionCount(10);\n// after\nbuilder.AddAzureCosmosDB(\"cosmos\").RunAsVNextEmulator(); // partition count not configurable on vNext","handlingStrategy":"validation","validationCode":"if (builder.Resource.InnerResource.IsVNextEmulator) { /* skip WithPartitionCount */ }","typeGuard":null,"tryCatchPattern":"try { builder.WithPartitionCount(10); } catch (NotSupportedException) { /* vNext emulator: knob unsupported, ignore */ }","preventionTips":["Only call WithPartitionCount for the classic Windows emulator.","Review emulator tuning calls when migrating to RunAsVNextEmulator.","Gate tuning calls on IsVNextEmulator."],"tags":["cosmosdb","emulator","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}