{"record":{"id":"77dac91a9718b4fb","repo":"microsoft/aspire","slug":"failed-to-resolve-connection-id-for-azure-ai-search-tool","errorCode":null,"errorMessage":"Failed to resolve connection ID for Azure AI Search tool '{Name}'. The Foundry project connection may not have been provisioned correctly.","messagePattern":"Failed to resolve connection ID for Azure AI Search tool '(.+?)'\\. The Foundry project connection may not have been provisioned correctly\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Foundry/ToolResources/AzureAISearchToolResource.cs","lineNumber":69,"sourceCode":"    /// </summary>\n    internal AzureCognitiveServicesProjectConnectionResource? Connection { get; set; }\n\n    /// <inheritdoc/>\n    public override async Task<ResponseTool> ToAgentToolAsync(CancellationToken cancellationToken = default)\n    {\n        if (Connection is null)\n        {\n            throw new InvalidOperationException(\n                $\"Azure AI Search tool '{Name}' does not have a backing resource configured. \" +\n                \"Call .WithReference(searchResource) to link it to an Azure AI Search resource.\");\n        }\n\n        // The connection ID output is resolved after infrastructure provisioning\n        var connectionIdRef = new BicepOutputReference(\"id\", Connection);\n        var connectionId = await connectionIdRef.GetValueAsync(cancellationToken).ConfigureAwait(false);\n        if (string.IsNullOrEmpty(connectionId))\n        {\n            throw new InvalidOperationException(\n                $\"Failed to resolve connection ID for Azure AI Search tool '{Name}'. \" +\n                \"The Foundry project connection may not have been provisioned correctly.\");\n        }\n\n        var index = new AzureAISearchToolIndex\n        {\n            ProjectConnectionId = connectionId,\n            IndexName = IndexName\n        };\n        var options = new AzureAISearchToolOptions([index]);\n        return new AzureAISearchTool(options);\n    }\n}\n","sourceCodeStart":51,"sourceCodeEnd":83,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Foundry/ToolResources/AzureAISearchToolResource.cs#L51-L83","documentation":"The AI Search tool resolves its connection ID from the backing connection's 'id' Bicep output, which only exists after infrastructure provisioning succeeds. An empty result means the Foundry project connection was not provisioned (or produced no id output), so the agent tool cannot reference it.","triggerScenarios":"ToAgentToolAsync runs during deployment, BicepOutputReference.GetValueAsync for output 'id' returns null/empty — typically because provisioning failed, the connection resource was not deployed, or the output name changed.","commonSituations":"Partial Azure deployments; azd provision failures earlier in the pipeline; using the tool locally before any deployment; Azure resource quota or region issues preventing the connection from being created.","solutions":["Re-run the Azure provisioning step (aspire publish/deploy or azd provision) and confirm it completes without errors.","Inspect the deployed Foundry project connections in the Azure portal to confirm the connection exists.","Check the bicep/infrastructure output names ('id') match what the connection resource emits.","If repeated, delete and re-create the Foundry project connection resources to clear stuck state."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"var id = await connectionResource.WaitUntilHealthyAsync()?.GetValueAsync(ct); if (string.IsNullOrEmpty(id)) { /* provisioning incomplete; retry or fail fast */ }","typeGuard":null,"tryCatchPattern":"try\n{\n    await agent.DeployAsync(ct);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Failed to resolve connection ID\"))\n{\n    logger.LogError(ex, \"Search connection not provisioned; re-run provisioning.\");\n    throw;\n}","preventionTips":["Ensure azd/aspire provisioning completes before deploying agents.","Monitor Azure provisioning logs for connection creation failures.","Avoid deploying from an AppHost model that was never provisioned."],"tags":["azure","foundry","ai-search","provisioning","bicep-output"],"backgroundTag":"empty-required-field","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"}