{"record":{"id":"a639f7fbbef9479b","repo":"microsoft/aspire","slug":"project-project-name-does-not-have-a-valid-connection-string","errorCode":null,"errorMessage":"Project '{project.Name}' does not have a valid connection string.","messagePattern":"Project '(.+?)' does not have a valid connection string\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Foundry/HostedAgent/AzureHostedAgentResource.cs","lineNumber":163,"sourceCode":"    }\n\n    /// <summary>\n    /// Deploys the specified agent to the given Microsoft Foundry project.\n    /// </summary>\n    private async Task<ProjectsAgentVersion> DeployAsync(PipelineStepContext context, AzureCognitiveServicesProjectResource project)\n    {\n        ArgumentNullException.ThrowIfNull(project);\n\n        var azureEnvironment = context.Model.Resources.OfType<AzureEnvironmentResource>().FirstOrDefault() ??\n            throw new InvalidOperationException(\"AzureEnvironmentResource must be present in the application model.\");\n\n        var provisioningContext = await azureEnvironment.ProvisioningContextTask.Task.ConfigureAwait(false);\n        var credential = provisioningContext.Credential;\n\n        var projectEndpoint = await project.Endpoint.GetValueAsync(context.CancellationToken).ConfigureAwait(false);\n        if (string.IsNullOrEmpty(projectEndpoint))\n        {\n            throw new InvalidOperationException($\"Project '{project.Name}' does not have a valid connection string.\");\n        }\n        var def = await ToHostedAgentConfigurationAsync(context).ConfigureAwait(false);\n        var options = def.ToProjectsAgentVersionCreationOptions(Target.Name);\n\n        var projectClient = new AIProjectClient(new Uri(projectEndpoint), credential);\n        var result = await projectClient.AgentAdministrationClient.CreateAgentVersionAsync(\n            Name,\n            options,\n            cancellationToken: context.CancellationToken\n        ).ConfigureAwait(false);\n\n        await UpdateAgentEndpointProtocolsAsync(projectClient.AgentAdministrationClient, def, context.CancellationToken).ConfigureAwait(false);\n\n        // Foundry should do this automatically in the future.\n        await AssignFoundryRoleToAgentIdentityAsync(context, project, result.Value, provisioningContext).ConfigureAwait(false);\n\n        return result.Value;\n    }","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Foundry/HostedAgent/AzureHostedAgentResource.cs#L145-L181","documentation":"During deployment, AzureHostedAgentResource.DeployAsync reads the linked Azure AI Foundry project's endpoint and requires it to be a valid, non-empty connection string. The library throws this error when the project resource's Endpoint resolves to null or empty, because the AIProjectClient cannot be constructed without a project endpoint URL.","triggerScenarios":"Deploying an app whose AzureCognitiveServicesProjectResource endpoint expression yields an empty value — e.g. the project endpoint output was never assigned during provisioning, or the endpoint callback returned an empty string.","commonSituations":"Provisioning failed or was skipped so the project endpoint output was never populated; the hosted agent references a project resource whose endpoint was not configured; publishing without running the provisioning step that sets the endpoint.","solutions":["Ensure the AI Foundry project resource is provisioned before the hosted agent's endpoint value is read (await deployment of the environment first)","Verify the project resource's Endpoint/connection string expression is wired to the deployment output that contains the endpoint URL","Check the provisioning log for errors indicating the Foundry project endpoint output was not produced","Validate locally that project.Endpoint resolves to an https URL of the form https://<resource>.services.ai.azure.com/api/projects/<project>"],"exampleFix":"// before\nvar agent = builder.AddHostedAgent(\"agent\") // project endpoint never populated\n    .WithProject(project);\n// after\nvar project = builder.AddAzureCognitiveServicesProject(\"foundry-project\") // provisioned, endpoint output set\n    ...\nvar agent = builder.AddHostedAgent(\"agent\")\n    .WithProject(project);","handlingStrategy":"validation","validationCode":"var endpoint = await project.Endpoint.GetValueAsync(ct);\nif (string.IsNullOrWhiteSpace(endpoint))\n    throw new InvalidOperationException($\"Project '{project.Name}' endpoint is not set; ensure the Foundry project is provisioned before deploying hosted agents.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    await resource.DeployAsync(context);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"does not have a valid connection string\"))\n{\n    logger.LogError(ex, \"Foundry project endpoint missing; verify provisioning completed.\");\n    throw;\n}","preventionTips":["Always provision the AI Foundry project environment before deploying hosted agents","Assert project.Endpoint resolves to an https URL in a pre-deployment check","Log the resolved endpoint early to catch empty values before deployment"],"tags":["azure","foundry","deployment","connection-string"],"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"}