microsoft/aspire · error · InvalidOperationException
Bing Grounding tool ' ' already has a connection configured.
Error message
Bing Grounding tool '{tool.Resource.Name}' already has a connection configured. What it means
A Bing Grounding tool may have only one connection configured. This WithReference overload throws when tool.Resource.Connection is already set, regardless of which overload set it, to prevent overwriting an existing backing connection.
Solutions
- Keep exactly one WithReference call per Bing Grounding tool; delete the redundant one.
- If the backing connection must change, recreate the tool via AddBingGroundingTool with the desired reference.
- Audit helper/extension code for repeated configuration of the same tool builder.
Example fix
// before
bingTool.WithReference("my-bing-conn");
bingTool.WithReference(bingConnectionBuilder);
// after
bingTool.WithReference(bingConnectionBuilder); Defensive patterns
Strategy: validation
Validate before calling
if (bingToolBuilder.Resource.Connection is not null) { /* skip additional WithReference */ } Type guard
bool isUnconfigured(FoundryToolResource t) => t.Connection is null;
Prevention
- Pick one WithReference overload per tool and stick to it.
- Wrap tool configuration in a single helper method.
- Code-review tool wiring for double configuration.
When it happens
Trigger: Calling WithReference(bing) on a Bing Grounding tool builder that already has a Connection — e.g. a prior WithReference with a BingGroundingConnectionResource, a string connection name, or a ParameterResource.
Common situations: Calling WithReference multiple times while trying different overloads; samples merged from different sources; helper methods that configure the tool more than once.
Understand the failure class
Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.
Related errors
- Azure AI Search tool
- Bing Grounding tool ' ' does not have a project connection…
- 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/75b596bfbd9fda9f.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Foundry/PromptAgent/PromptAgentBuilderExtensions.cs:449
/// <summary>
/// Links a Bing Grounding tool to a Bing Search resource or connection.
/// </summary>
[AspireExport("withBingReference", MethodName = "withReference")]
internal static IResourceBuilder<BingGroundingToolResource> WithReference(
this IResourceBuilder<BingGroundingToolResource> tool,
[AspireUnion(
typeof(IResourceBuilder<BingGroundingConnectionResource>),
typeof(string),
typeof(IResourceBuilder<ParameterResource>))]
object bingReference)
{
ArgumentNullException.ThrowIfNull(tool);
ArgumentNullException.ThrowIfNull(bingReference);
if (tool.Resource.Connection is not null)
{
throw new InvalidOperationException(
$"Bing Grounding tool '{tool.Resource.Name}' already has a connection configured.");
}
switch (bingReference)
{
case IResourceBuilder<BingGroundingConnectionResource> connectionBuilder:
tool.Resource.Connection = connectionBuilder.Resource;
break;
case string bingResourceId:
ArgumentException.ThrowIfNullOrEmpty(bingResourceId);
var projectBuilder = tool.ApplicationBuilder.CreateResourceBuilder(tool.Resource.Project);
var connection = projectBuilder.AddBingGroundingConnection($"{tool.Resource.Name}-conn", bingResourceId);
tool.Resource.Connection = connection.Resource;
break;
case IResourceBuilder<ParameterResource> parameterBuilder:
var paramProjectBuilder = tool.ApplicationBuilder.CreateResourceBuilder(tool.Resource.Project);View on GitHub (pinned to 25830f84bd)