microsoft/aspire · error · InvalidOperationException

Failed to resolve connection ID for Bing Grounding tool

Error message

Failed to resolve connection ID for Bing Grounding tool '{Name}'. The Foundry project connection may not have been provisioned correctly.

What it means

Thrown by BingGroundingToolResource.ToAgentToolAsync when the Bicep output 'id' on the Foundry project's Bing connection resource resolves to null or empty. The library needs the provisioned connection's resource ID to build the BingGroundingSearchConfiguration; without it the grounding tool cannot be wired up. This indicates the connection resource did not complete provisioning or produced no id output.

Solutions

  1. Verify the Bing Grounding connection exists in the Foundry project in the Azure portal and is in a succeeded provisioning state.
  2. Re-run the deployment (redeploy the App Host / publish) so the connection Bicep resource re-executes and emits the id output.
  3. Confirm the connection name used when creating BingGroundingToolResource matches the provisioned connection exactly.
  4. Check ARM deployment logs for errors on the connection resource and fix the underlying deployment failure.

Example fix

// before
var bing = foundry.AddBingGroundingTool("bing"); // connection name 'bing' not provisioned
// after
var bing = foundry.AddBingGroundingTool("my-bing-connection"); // matches the provisioned connection name in the Foundry project
Defensive patterns

Strategy: try-catch

Validate before calling

// Before building the agent tool, confirm the connection exists in the Foundry project:
// var project = await foundryProjectResource.GetAsync(ct);
// ensure a connection with the expected Bing resource name and Succeeded state exists.

Try / catch

try
{
    await bingTool.ToAgentToolAsync(ct);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("Failed to resolve connection ID"))
{
    logger.LogError(ex, "Bing Grounding connection not provisioned for {Tool}; check the Foundry project connections.", bingTool.Name);
    throw;
}

Prevention

When it happens

Trigger: Calling WithAgentTool/ToAgentToolAsync on a BingGroundingToolResource whose underlying Connection Bicep resource has been provisioned but returned an empty 'id' output — e.g. deployment partially failed, the Bing resource name is wrong, or the Foundry project lacks the Bing connection.

Common situations: The Bing Grounding connection was deleted or renamed in the Azure portal while the app model still references it; ARM deployed the connection but it returned no id; running locally against a Foundry project where the Bing connection was never provisioned; casing/typo in the connection name passed to the Bing grounding tool builder.

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/8ec1655e3646cbc3. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.Foundry/ToolResources/BingGroundingToolResource.cs:67

    /// Gets or sets the Bing grounding connection resource for the Bing Search service.
    /// </summary>
    internal BingGroundingConnectionResource? Connection { get; set; }

    /// <inheritdoc/>
    public override async Task<ResponseTool> ToAgentToolAsync(CancellationToken cancellationToken = default)
    {
        if (Connection is null)
        {
            throw new InvalidOperationException(
                $"Bing Grounding tool '{Name}' does not have a project connection. " +
                "Ensure the tool was added using AddBingGroundingTool().");
        }

        var connectionIdRef = new BicepOutputReference("id", Connection);
        var connectionId = await connectionIdRef.GetValueAsync(cancellationToken).ConfigureAwait(false);
        if (string.IsNullOrEmpty(connectionId))
        {
            throw new InvalidOperationException(
                $"Failed to resolve connection ID for Bing Grounding tool '{Name}'. " +
                "The Foundry project connection may not have been provisioned correctly.");
        }

        var config = new BingGroundingSearchConfiguration(connectionId);
        var options = new BingGroundingSearchToolOptions([config]);
        return new BingGroundingTool(options);
    }
}

View on GitHub (pinned to 25830f84bd)