{"record":{"id":"06122e52202942a0","repo":"microsoft/aspire","slug":"capability-host-name-on-project-projectname-requires-a","errorCode":null,"errorMessage":"Capability host '{Name}' on project '{projectName}' requires a CosmosDB resource. Call WithCosmosDB() on the capability host builder.","messagePattern":"Capability host '(.+?)' on project '(.+?)' requires a CosmosDB resource\\. Call WithCosmosDB\\(\\) on the capability host builder\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Foundry/Project/ProjectResource.cs","lineNumber":338,"sourceCode":"    /// The Storage resource to use for file storage.\n    /// </summary>\n    public AzureStorageResource? Storage { get; set; }\n\n    /// <summary>\n    /// The Azure Search resource to use for vector search capabilities.\n    /// </summary>\n    public AzureSearchResource? Search { get; set; }\n\n    /// <summary>\n    /// An OpenAI-type Microsoft Foundry account to use for AI model calls, if any.\n    /// </summary>\n    public FoundryResource? AzureOpenAI { get; set; }\n\n    internal void Validate(string projectName)\n    {\n        if (CosmosDB is null)\n        {\n            throw new InvalidOperationException($\"Capability host '{Name}' on project '{projectName}' requires a CosmosDB resource. Call WithCosmosDB() on the capability host builder.\");\n        }\n        if (Storage is null)\n        {\n            throw new InvalidOperationException($\"Capability host '{Name}' on project '{projectName}' requires a Storage resource. Call WithStorage() on the capability host builder.\");\n        }\n        if (Search is null)\n        {\n            throw new InvalidOperationException($\"Capability host '{Name}' on project '{projectName}' requires a Search resource. Call WithSearch() on the capability host builder.\");\n        }\n    }\n}\n\n/// <summary>\n/// A fluent builder for configuring a capability host on a Microsoft Foundry project.\n/// </summary>\npublic class CapabilityHostBuilder(IResourceBuilder<AzureCognitiveServicesProjectResource> projectBuilder, CapabilityHostConfiguration configuration)\n{\n    /// <summary>","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Foundry/Project/ProjectResource.cs#L320-L356","documentation":"A capability host on a Foundry project requires CosmosDB (and Storage/Search) backing resources. The internal Validate method, run when the capability host is finalized, throws this InvalidOperationException if the CosmosDB property was never assigned via WithCosmosDB().","triggerScenarios":"Creating a capability host with AddCapabilityHost / withCapabilityHost and finalizing it without calling WithCosmosDB() (or withCapabilityHost equivalent) with a CosmosDB resource.","commonSituations":"Configuring only Storage or Search and forgetting CosmosDB; conditionally skipping CosmosDB in some environments; a partially migrated capability-host configuration where one With* call was dropped.","solutions":["Call .WithCosmosDB(cosmosDbBuilder) on the capability host before finalizing","Ensure the CosmosDB resource is created (AddAzureCosmosDB) and passed to the capability host","Check that no early-return or conditional branch skips the WithCosmosDB call"],"exampleFix":"// before\nproject.AddCapabilityHost(\"cap\").WithStorage(storage).WithSearch(search);\n\n// after\nproject.AddCapabilityHost(\"cap\").WithCosmosDB(cosmosDb).WithStorage(storage).WithSearch(search);","handlingStrategy":"validation","validationCode":"if (cosmosDb is null)\n{\n    throw new InvalidOperationException(\"Capability host requires a CosmosDB resource.\");\n}\nproject.AddCapabilityHost(name).WithCosmosDB(cosmosDb);","typeGuard":null,"tryCatchPattern":"try { /* finalize capability host / run app host */ }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"requires a CosmosDB resource\"))\n{\n    // Attach a CosmosDB resource and retry.\n}","preventionTips":["Always call WithCosmosDB when creating a capability host","Keep all required With* calls (CosmosDB, Storage, Search) together in one helper","Validate capability-host configuration completeness before running the AppHost"],"tags":["csharp","aspire","azure","capability-host","missing-dependency"],"backgroundTag":"missing-dependency","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"}