{"record":{"id":"7c8ddd01fea8195d","repo":"microsoft/aspire","slug":"provisionable-resource-for-aspire-resource-builder-resource","errorCode":null,"errorMessage":"Provisionable resource for Aspire resource '{builder.Resource.Name}' not found in infrastructure.","messagePattern":"Provisionable resource for Aspire resource '(.+?)' not found in infrastructure\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Foundry/Project/AzureCognitiveServicesBase.cs","lineNumber":114,"sourceCode":"/// </summary>\npublic static class AzureProvisionableAspireResourceExtensions\n{\n    /// <summary>\n    /// Configure the underlying Azure ProvisioningResource for situations\n    /// where additional customization is needed.\n    /// </summary>\n    /// <typeparam name=\"A\">The type of the Aspire resource.</typeparam>\n    /// <typeparam name=\"P\">The type of the underlying Provisionable resource</typeparam>\n    /// <param name=\"builder\">The resource builder.</param>\n    /// <param name=\"configure\">An callback to configure the Provisionable resource.</param>\n    /// <returns>The resource builder.</returns>\n    internal static IResourceBuilder<A> WithConfiguration<A, P>(this IResourceBuilder<A> builder, Action<P> configure)\n        where A : AzureProvisionableAspireResource<P>\n        where P : ProvisionableResource\n    {\n        builder.ConfigureInfrastructure(infra =>\n        {\n            var r = AzureProvisionableAspireResource<P>.GetProvisionableResource(infra, builder.Resource.GetBicepIdentifier()) ?? throw new InvalidOperationException($\"Provisionable resource for Aspire resource '{builder.Resource.Name}' not found in infrastructure.\");\n            configure(r);\n        });\n        return builder;\n    }\n}\n","sourceCodeStart":96,"sourceCodeEnd":120,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Foundry/Project/AzureCognitiveServicesBase.cs#L96-L120","documentation":"WithConfiguration locates the provisionable resource inside the resource's infrastructure bicep by Bicep identifier before applying user configuration. When AzureProvisionableAspireResource<P>.GetProvisionableResource cannot find a matching provisionable resource in the infrastructure, this InvalidOperationException is thrown, meaning the expected backing Azure resource is missing from the generated module.","triggerScenarios":"Calling a WithConfiguration-based extension (e.g. WithDeployment, WithConnection configuration helpers on AzureCognitiveServices resources) before the infrastructure add step ran, or after the underlying provisionable resource was removed/renamed so the identifier no longer matches.","commonSituations":"Ordering problems where configuration callbacks run on an empty infrastructure; custom infrastructure modifications that removed or renamed the resource; passing a builder whose resource was transformed during publish-mode model manipulation.","solutions":["Ensure the API that adds the provisionable resource to the infrastructure (the main Add*/resource creation call) executes before any WithConfiguration call.","Do not remove or rename the resource inside other ConfigureInfrastructure callbacks.","Compare builder.Resource.GetBicepIdentifier() with the identifier used when the provisionable resource was added; align them."],"exampleFix":"// before\nvar project = foundry.AddProject(...);\nproject.WithConfiguration<...>(c => c.SomeProp = x); // infrastructure not yet populated\n\n// after\nvar project = foundry.AddProject(...); // ensure provisioning infra built first\nproject.WithConfiguration<...>(c => c.SomeProp = x); // after resource creation","handlingStrategy":"validation","validationCode":"// ensure infrastructure contains the resource before configuring\nvar infra = /* resource infrastructure */;\nbool exists = infra.GetProvisionableResources().Any(r => r.BicepIdentifier == builder.Resource.GetBicepIdentifier());","typeGuard":null,"tryCatchPattern":"try { builder.WithConfiguration(cfg => ...); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"not found in infrastructure\")) { /* ensure resource creation ran first */ }","preventionTips":["Call configuration extensions only after the resource-creating Add* API has executed.","Never remove or rename the provisionable resource in other ConfigureInfrastructure callbacks.","Keep Bicep identifiers stable and derived from the resource name."],"tags":["azure-ai-foundry","aspire-hosting","infrastructure","provisioning"],"backgroundTag":"resource-not-found","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"}