microsoft/aspire · error · InvalidOperationException

Provisionable resource for Aspire resource

Error message

Provisionable resource for Aspire resource '{builder.Resource.Name}' not found in infrastructure.

What it means

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.

Solutions

  1. Ensure the API that adds the provisionable resource to the infrastructure (the main Add*/resource creation call) executes before any WithConfiguration call.
  2. Do not remove or rename the resource inside other ConfigureInfrastructure callbacks.
  3. Compare builder.Resource.GetBicepIdentifier() with the identifier used when the provisionable resource was added; align them.

Example fix

// before
var project = foundry.AddProject(...);
project.WithConfiguration<...>(c => c.SomeProp = x); // infrastructure not yet populated

// after
var project = foundry.AddProject(...); // ensure provisioning infra built first
project.WithConfiguration<...>(c => c.SomeProp = x); // after resource creation
Defensive patterns

Strategy: validation

Validate before calling

// ensure infrastructure contains the resource before configuring
var infra = /* resource infrastructure */;
bool exists = infra.GetProvisionableResources().Any(r => r.BicepIdentifier == builder.Resource.GetBicepIdentifier());

Try / catch

try { builder.WithConfiguration(cfg => ...); } catch (InvalidOperationException ex) when (ex.Message.Contains("not found in infrastructure")) { /* ensure resource creation ran first */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/7c8ddd01fea8195d. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.Foundry/Project/AzureCognitiveServicesBase.cs:114

/// </summary>
public static class AzureProvisionableAspireResourceExtensions
{
    /// <summary>
    /// Configure the underlying Azure ProvisioningResource for situations
    /// where additional customization is needed.
    /// </summary>
    /// <typeparam name="A">The type of the Aspire resource.</typeparam>
    /// <typeparam name="P">The type of the underlying Provisionable resource</typeparam>
    /// <param name="builder">The resource builder.</param>
    /// <param name="configure">An callback to configure the Provisionable resource.</param>
    /// <returns>The resource builder.</returns>
    internal static IResourceBuilder<A> WithConfiguration<A, P>(this IResourceBuilder<A> builder, Action<P> configure)
        where A : AzureProvisionableAspireResource<P>
        where P : ProvisionableResource
    {
        builder.ConfigureInfrastructure(infra =>
        {
            var r = AzureProvisionableAspireResource<P>.GetProvisionableResource(infra, builder.Resource.GetBicepIdentifier()) ?? throw new InvalidOperationException($"Provisionable resource for Aspire resource '{builder.Resource.Name}' not found in infrastructure.");
            configure(r);
        });
        return builder;
    }
}

View on GitHub (pinned to 25830f84bd)