{"record":{"id":"930a04a72e3a28f3","repo":"microsoft/aspire","slug":"unsupported-bing-reference-type-bingreference-gettype-name","errorCode":null,"errorMessage":"Unsupported Bing reference type '{bingReference.GetType().Name}'. Expected IResourceBuilder<BingGroundingConnectionResource>, string, or IResourceBuilder<ParameterResource>.","messagePattern":"Unsupported Bing reference type '(.+?)'\\. Expected IResourceBuilder<BingGroundingConnectionResource>, string, or IResourceBuilder<ParameterResource>\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Foundry/PromptAgent/PromptAgentBuilderExtensions.cs","lineNumber":473,"sourceCode":"            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);\n                var paramConnection = paramProjectBuilder.AddBingGroundingConnection($\"{tool.Resource.Name}-conn\", parameterBuilder);\n                tool.Resource.Connection = paramConnection.Resource;\n                break;\n\n            default:\n                throw new ArgumentException(\n                    $\"Unsupported Bing reference type '{bingReference.GetType().Name}'. \" +\n                    \"Expected IResourceBuilder<BingGroundingConnectionResource>, string, or IResourceBuilder<ParameterResource>.\",\n                    nameof(bingReference));\n        }\n\n        return tool;\n    }\n\n    // ──────────────────────────────────────────────────────────────\n    // Configuration-only tools\n    // ──────────────────────────────────────────────────────────────\n\n    /// <summary>\n    /// Adds a SharePoint grounding tool to a Microsoft Foundry project, enabling agents to\n    /// search data from SharePoint sites configured as Foundry project connections.\n    /// </summary>\n    /// <param name=\"project\">The <see cref=\"IResourceBuilder{T}\"/> for the Microsoft Foundry project.</param>\n    /// <ats-param name=\"project\">The Microsoft Foundry project resource builder.</ats-param>","sourceCodeStart":455,"sourceCodeEnd":491,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Foundry/PromptAgent/PromptAgentBuilderExtensions.cs#L455-L491","documentation":"The Bing Grounding WithReference overload accepts only an IResourceBuilder<BingGroundingConnectionResource>, a string (connection name), or an IResourceBuilder<ParameterResource>. Any other object falls into the switch's default case and raises this ArgumentException naming the actual runtime type received.","triggerScenarios":"Passing an unsupported argument type to WithReference on a Bing tool — e.g. IResourceBuilder<ParameterResource> confusion with a raw ParameterResource, a connection string value, or an unrelated resource builder.","commonSituations":"Misreading the overload's contract and passing a connection string literal or a different resource type; refactors that change argument types without updating call sites.","solutions":["Pass one of the accepted types: a Bing connection resource builder, a string connection name, or a parameter resource builder.","If you have a connection string, wrap it in a parameter resource: builder.AddParameter(\"bing-key\") and pass that builder.","Check the PromptAgentBuilderExtensions API docs for the exact accepted overloads."],"exampleFix":"// before\nbingTool.WithReference(\"https://my-bing-endpoint\");\n// after\nvar bingParam = builder.AddParameter(\"bing-connection\");\nbingTool.WithReference(bingParam);","handlingStrategy":"type-guard","validationCode":"if (bingRef is not IResourceBuilder<BingGroundingConnectionResource> && bingRef is not string && bingRef is not IResourceBuilder<ParameterResource>) throw new ArgumentException(nameof(bingRef));","typeGuard":"static bool IsValidBingReference(object bingRef) =>\n    bingRef is IResourceBuilder<BingGroundingConnectionResource>\n    || bingRef is string\n    || bingRef is IResourceBuilder<ParameterResource>;","tryCatchPattern":"try\n{\n    bingTool.WithReference(bingRef);\n}\ncatch (ArgumentException ex)\n{\n    logger.LogError(ex, \"Unsupported Bing reference type {Type}\", bingRef.GetType().Name);\n    throw;\n}","preventionTips":["Pass a Bing connection resource builder, string, or parameter resource builder — nothing else.","Wrap raw connection strings in AddParameter before referencing.","Check the WithReference overload signature in PromptAgentBuilderExtensions when unsure."],"tags":["azure","foundry","bing","argument-type","tool"],"backgroundTag":"invalid-argument-value","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}