{"record":{"id":"2f0db47fd4e09ad1","repo":"microsoft/aspire","slug":"resource-must-be-a-supported-capability-host-resource","errorCode":null,"errorMessage":"Resource must be a supported capability host resource.","messagePattern":"Resource must be a supported capability host resource\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Foundry/Project/ProjectBuilderExtension.cs","lineNumber":268,"sourceCode":"    [AspireExport]\n    internal static IResourceBuilder<AzureCognitiveServicesProjectResource> WithCapabilityHost(\n        this IResourceBuilder<AzureCognitiveServicesProjectResource> builder,\n        [AspireUnion(\n            typeof(IResourceBuilder<AzureCosmosDBResource>),\n            typeof(IResourceBuilder<AzureStorageResource>),\n            typeof(IResourceBuilder<AzureSearchResource>),\n            typeof(IResourceBuilder<FoundryResource>))] object resource)\n    {\n        ArgumentNullException.ThrowIfNull(builder);\n        ArgumentNullException.ThrowIfNull(resource);\n\n        return resource switch\n        {\n            IResourceBuilder<AzureCosmosDBResource> cosmosDb => builder.WithCapabilityHostCosmosDB(cosmosDb),\n            IResourceBuilder<AzureStorageResource> storage => builder.WithCapabilityHostStorage(storage),\n            IResourceBuilder<AzureSearchResource> search => builder.WithCapabilityHostSearch(search),\n            IResourceBuilder<FoundryResource> openAI => builder.WithCapabilityHostAzureOpenAI(openAI),\n            _ => throw new ArgumentException(\"Resource must be a supported capability host resource.\", nameof(resource))\n        };\n    }\n\n    /// <summary>\n    /// Adds a model deployment to the parent Microsoft Foundry resource of the Microsoft Foundry project.\n    /// </summary>\n    /// <param name=\"builder\">Aspire resource builder for a project</param>\n    /// <param name=\"name\">Name to give the model deployment</param>\n    /// <param name=\"model\">The <see cref=\"FoundryModel\"/> to deploy.</param>\n    /// <returns>A reference to the <see cref=\"IResourceBuilder{T}\"/> for the deployment resource.</returns>\n    [AspireExportIgnore(Reason = \"Polyglot AppHosts use the internal addModelDeployment dispatcher export.\")]\n    public static IResourceBuilder<FoundryDeploymentResource> AddModelDeployment(\n        this IResourceBuilder<AzureCognitiveServicesProjectResource> builder,\n        [ResourceName] string name,\n        FoundryModel model)\n    {\n        ArgumentNullException.ThrowIfNull(builder);\n        ArgumentException.ThrowIfNullOrEmpty(name);","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Foundry/Project/ProjectBuilderExtension.cs#L250-L286","documentation":"WithCapabilityHost only accepts CosmosDB, Storage, Search, or Foundry (Azure OpenAI) resource builders as the capability-host backing resource. Any other resource type falls through the switch and throws this ArgumentException naming the offending parameter.","triggerScenarios":"Passing e.g. an IResourceBuilder<RedisCacheResource>, a SQL resource, or any non-supported Azure resource to the withCapabilityHost polyglot overload / WithCapabilityHost switch in ProjectBuilderExtension.cs.","commonSituations":"Using the wrong overload of WithCapabilityHost so the resource argument is interpreted as the backing resource instead of the project; passing a generic container resource expecting it to be wired up automatically.","solutions":["Pass one of the supported resource builders: AzureCosmosDBResource, AzureStorageResource, AzureSearchResource, or FoundryResource","Check which WithCapabilityHost overload you are calling; ensure the project builder is the 'this' receiver, not passed as the resource argument","Add the required Azure resource (e.g. AddAzureSearch) and pass its builder instead"],"exampleFix":"// before\nproject.WithCapabilityHost(cosmosDb, storage, search, redisBuilder);\n\n// after\nproject.WithCapabilityHost(cosmosDb, storage, search, foundryBuilder);","handlingStrategy":"type-guard","validationCode":"bool isSupported = resource is IResourceBuilder<AzureCosmosDBResource>\n    or IResourceBuilder<AzureStorageResource>\n    or IResourceBuilder<AzureSearchResource>\n    or IResourceBuilder<FoundryResource>;","typeGuard":"static bool IsCapabilityHostResource(IResourceBuilder<IResource> r) =>\n    r is IResourceBuilder<AzureCosmosDBResource>\n    or IResourceBuilder<AzureStorageResource>\n    or IResourceBuilder<AzureSearchResource>\n    or IResourceBuilder<FoundryResource>;","tryCatchPattern":"try { project.WithCapabilityHost(resource, ...); }\ncatch (ArgumentException ex) when (ex.ParamName == \"resource\")\n{\n    // Unsupported resource type; map or reject it.\n}","preventionTips":["Only pass CosmosDB, Storage, Search, or Foundry resource builders to WithCapabilityHost","Check the overload signature before calling; keep the project builder as the extension receiver","Create dedicated Azure resources instead of generic containers for capability hosts"],"tags":["csharp","aspire","azure","argument-type"],"backgroundTag":"incompatible-source-type","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"}