microsoft/aspire · error · InvalidOperationException
Bing Grounding tool ' ' does not have a project connection…
Error message
Bing Grounding tool '{Name}' does not have a project connection. Ensure the tool was added using AddBingGroundingTool(). What it means
A Bing Grounding tool must carry a project connection assigned by AddBingGroundingTool (and its WithReference). ToAgentToolAsync throws when Connection is null, meaning the tool was constructed without going through the supported AddBingGroundingTool path or was never wired to a connection.
Solutions
- Use AddBingGroundingTool() on the Foundry project builder to create the tool, then call WithReference with a Bing connection, string, or parameter resource.
- Verify tool.Resource.Connection is non-null before deployment.
- Replace any manual construction of BingGroundingToolResource with the builder API.
Example fix
// before
var bingTool = new BingGroundingToolResource("bing");
// after
var bingTool = project.AddBingGroundingTool("bing")
.WithReference(bingConnection); Defensive patterns
Strategy: validation
Validate before calling
if (bingToolBuilder.Resource.Connection is null) throw new InvalidOperationException("Add the tool via AddBingGroundingTool() and call WithReference."); Type guard
bool isLinked(BingGroundingToolResource t) => t.Connection is not null;
Prevention
- Create Bing tools only through AddBingGroundingTool().
- Always pair tool creation with a WithReference call.
- Assert Connection non-null before adding tools to agents.
When it happens
Trigger: Creating a BingGroundingToolResource directly or adding it without a connection, then deploying an agent that includes it.
Common situations: Manually instantiating the tool resource instead of using the builder API; calling WithReference never ran due to conditionals; refactors that bypass AddBingGroundingTool.
Understand the failure class
Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.
Related errors
- Azure AI Search tool
- Bing Grounding tool ' ' already has a connection configured.
- Unsupported Bing reference type
- Azure AI Search tool
- Tool ' ' belongs to project ' ' but agent ' ' belongs to…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/3cb939b3fe12713b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Foundry/ToolResources/BingGroundingToolResource.cs:58
/// <param name="project">The parent Foundry project resource.</param>
public BingGroundingToolResource(
[ResourceName] string name,
AzureCognitiveServicesProjectResource project)
: base(name, project)
{
}
/// <summary>
/// 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)