{"record":{"id":"75b596bfbd9fda9f","repo":"microsoft/aspire","slug":"bing-grounding-tool-tool-resource-name-already-has-a","errorCode":null,"errorMessage":"Bing Grounding tool '{tool.Resource.Name}' already has a connection configured.","messagePattern":"Bing Grounding tool '(.+?)' already has a connection configured\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Foundry/PromptAgent/PromptAgentBuilderExtensions.cs","lineNumber":449,"sourceCode":"\n    /// <summary>\n    /// Links a Bing Grounding tool to a Bing Search resource or connection.\n    /// </summary>\n    [AspireExport(\"withBingReference\", MethodName = \"withReference\")]\n    internal static IResourceBuilder<BingGroundingToolResource> WithReference(\n        this IResourceBuilder<BingGroundingToolResource> tool,\n        [AspireUnion(\n            typeof(IResourceBuilder<BingGroundingConnectionResource>),\n            typeof(string),\n            typeof(IResourceBuilder<ParameterResource>))]\n        object bingReference)\n    {\n        ArgumentNullException.ThrowIfNull(tool);\n        ArgumentNullException.ThrowIfNull(bingReference);\n\n        if (tool.Resource.Connection is not null)\n        {\n            throw new InvalidOperationException(\n                $\"Bing Grounding tool '{tool.Resource.Name}' already has a connection configured.\");\n        }\n\n        switch (bingReference)\n        {\n            case IResourceBuilder<BingGroundingConnectionResource> connectionBuilder:\n                tool.Resource.Connection = connectionBuilder.Resource;\n                break;\n\n            case string bingResourceId:\n                ArgumentException.ThrowIfNullOrEmpty(bingResourceId);\n                var projectBuilder = tool.ApplicationBuilder.CreateResourceBuilder(tool.Resource.Project);\n                var connection = projectBuilder.AddBingGroundingConnection($\"{tool.Resource.Name}-conn\", bingResourceId);\n                tool.Resource.Connection = connection.Resource;\n                break;\n\n            case IResourceBuilder<ParameterResource> parameterBuilder:\n                var paramProjectBuilder = tool.ApplicationBuilder.CreateResourceBuilder(tool.Resource.Project);","sourceCodeStart":431,"sourceCodeEnd":467,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Foundry/PromptAgent/PromptAgentBuilderExtensions.cs#L431-L467","documentation":"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.","triggerScenarios":"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.","commonSituations":"Calling WithReference multiple times while trying different overloads; samples merged from different sources; helper methods that configure the tool more than once.","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."],"exampleFix":"// before\nbingTool.WithReference(\"my-bing-conn\");\nbingTool.WithReference(bingConnectionBuilder);\n// after\nbingTool.WithReference(bingConnectionBuilder);","handlingStrategy":"validation","validationCode":"if (bingToolBuilder.Resource.Connection is not null) { /* skip additional WithReference */ }","typeGuard":"bool isUnconfigured(FoundryToolResource t) => t.Connection is null;","tryCatchPattern":null,"preventionTips":["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."],"tags":["azure","foundry","bing","duplicate-configuration","tool"],"backgroundTag":"conflicting-config-options","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}