{"record":{"id":"986c63c2e3a19a72","repo":"microsoft/semantic-kernel","slug":"please-provide-a-valid-azureai-connectionstring","errorCode":null,"errorMessage":"Please provide a valid `AzureAI:ConnectionString` secret to run this sample. See the associated README.md for more details.","messagePattern":"Please provide a valid `AzureAI:ConnectionString` secret to run this sample\\. See the associated README\\.md for more details\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"dotnet/samples/Demos/ModelContextProtocolClientServer/MCPClient/Samples/AzureAIAgentWithMCPToolsSample.cs","lineNumber":93,"sourceCode":"    /// Creates an instance of <see cref=\"AzureAIAgent\"/> with the specified name and instructions.\n    /// </summary>\n    /// <param name=\"kernel\">The kernel instance.</param>\n    /// <param name=\"name\">The name of the agent.</param>\n    /// <param name=\"instructions\">The instructions for the agent.</param>\n    /// <returns>An instance of <see cref=\"AzureAIAgent\"/>.</returns>\n    private static async Task<AzureAIAgent> CreateAzureAIAgentAsync(Kernel kernel, string name, string instructions)\n    {\n        // Load and validate configuration\n        IConfigurationRoot config = new ConfigurationBuilder()\n            .AddUserSecrets<Program>()\n            .AddEnvironmentVariables()\n            .Build();\n\n        if (config[\"AzureAI:Endpoint\"] is not { } endpoint)\n        {\n            const string Message = \"Please provide a valid `AzureAI:ConnectionString` secret to run this sample. See the associated README.md for more details.\";\n            Console.Error.WriteLine(Message);\n            throw new InvalidOperationException(Message);\n        }\n\n        string modelId = config[\"AzureAI:ChatModelId\"] ?? \"gpt-4o-mini\";\n\n        // Create the Azure AI Agent\n        PersistentAgentsClient agentsClient = AzureAIAgent.CreateAgentsClient(endpoint, new AzureCliCredential());\n\n        PersistentAgent agent = await agentsClient.Administration.CreateAgentAsync(modelId, name, null, instructions);\n\n        return new AzureAIAgent(agent, agentsClient)\n        {\n            Kernel = kernel\n        };\n    }\n}\n","sourceCodeStart":75,"sourceCodeEnd":109,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/Demos/ModelContextProtocolClientServer/MCPClient/Samples/AzureAIAgentWithMCPToolsSample.cs#L75-L109","documentation":"CreateAzureAIAgentAsync checks config[\"AzureAI:Endpoint\"] and throws if it is not present. IMPORTANT discrepancy: the error message references `AzureAI:ConnectionString`, but the code actually checks `AzureAI:Endpoint`. So the message is misleading — supplying a ConnectionString alone will NOT satisfy this guard; you must supply an Endpoint. The agent is then created via AzureCliCredential using that endpoint.","triggerScenarios":"config[\"AzureAI:Endpoint\"] is null (the `is not { } endpoint` pattern fails). Even if AzureAI:ConnectionString is set, this still throws because the check is on Endpoint.","commonSituations":"User followed the message and set AzureAI:ConnectionString but not Endpoint; Azure AI project endpoint not copied from the portal; or env var uses the wrong key.","solutions":["Set AzureAI:Endpoint (the message's 'ConnectionString' reference is wrong — Endpoint is what is checked).","Report/fix the message-vs-key mismatch upstream so the hint is accurate.","Confirm an Azure CLI login exists since AzureCliCredential is used (`az login`).","Optionally set AzureAI:ChatModelId (defaults to gpt-4o-mini)."],"exampleFix":"// before (misleading message)\nif (config[\"AzureAI:Endpoint\"] is not { } endpoint)\n{\n    const string Message = \"Please provide a valid `AzureAI:ConnectionString` secret...\";\n    throw new InvalidOperationException(Message);\n}\n\n// after (correct, accurate message)\nif (config[\"AzureAI:Endpoint\"] is not { } endpoint)\n{\n    const string Message = \"Please provide a valid `AzureAI:Endpoint` secret to run this sample. See the associated README.md for more details.\";\n    Console.Error.WriteLine(Message);\n    throw new InvalidOperationException(Message);\n}","handlingStrategy":"validation","validationCode":"if (config[\"AzureAI:Endpoint\"] is not { } endpoint)\n    throw new InvalidOperationException(\n        \"Set AzureAI:Endpoint (note: the code checks Endpoint, NOT ConnectionString despite the message).\");","typeGuard":"static bool HasAzureAiEndpoint(IConfigurationRoot c) =>\n    !string.IsNullOrEmpty(c[\"AzureAI:Endpoint\"]);","tryCatchPattern":null,"preventionTips":["Supply AzureAI:Endpoint — the message naming ConnectionString is misleading.","Run `az login` since AzureCliCredential is used.","File/fix the upstream message so it points at the key actually checked."],"tags":["configuration","azure-ai","bug","samples"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}