{"record":{"id":"0934a3a21d7ca089","repo":"microsoft/semantic-kernel","slug":"azure-foundry-project-endpoint-is-not-set","errorCode":null,"errorMessage":"AZURE_FOUNDRY_PROJECT_ENDPOINT is not set.","messagePattern":"AZURE_FOUNDRY_PROJECT_ENDPOINT is not set\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/samples/AgentFrameworkMigration/AzureAIFoundry/Step01_Basics/Program.cs","lineNumber":12,"sourceCode":"﻿// Copyright (c) Microsoft. All rights reserved.\n\nusing Azure.AI.Agents.Persistent;\nusing Azure.AI.Projects;\nusing Azure.Identity;\nusing Microsoft.Agents.AI;\nusing Microsoft.SemanticKernel;\nusing Microsoft.SemanticKernel.Agents.AzureAI;\n\n#pragma warning disable SKEXP0110 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.\n\nvar azureEndpoint = Environment.GetEnvironmentVariable(\"AZURE_FOUNDRY_PROJECT_ENDPOINT\") ?? throw new InvalidOperationException(\"AZURE_FOUNDRY_PROJECT_ENDPOINT is not set.\");\nvar deploymentName = System.Environment.GetEnvironmentVariable(\"AZURE_FOUNDRY_PROJECT_DEPLOYMENT_NAME\") ?? \"gpt-4o\";\nvar userInput = \"Tell me a joke about a pirate.\";\n\nConsole.WriteLine($\"User Input: {userInput}\");\n\nawait SKAgentAsync();\nawait SKAgent_As_AFAgentAsync();\nawait AFAgentAsync();\n\nasync Task SKAgentAsync()\n{\n    Console.WriteLine(\"\\n=== SK Agent ===\\n\");\n\n    var azureAgentClient = AzureAIAgent.CreateAgentsClient(azureEndpoint, new AzureCliCredential());\n\n    PersistentAgent definition = await azureAgentClient.Administration.CreateAgentAsync(\n        deploymentName,\n        name: \"GenerateStory\",","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/AgentFrameworkMigration/AzureAIFoundry/Step01_Basics/Program.cs#L1-L30","documentation":"The Azure AI Foundry Basics migration sample throws InvalidOperationException when AZURE_FOUNDRY_PROJECT_ENDPOINT is null. This endpoint is distinct from a plain AZURE_OPENAI_ENDPOINT — it targets an Azure AI Foundry project, used to create cloud-hosted persistent agents via PersistentAgentsClient and AzureAIAgent. The sample compares SK's AzureAIAgent against the Agent Framework equivalent.","triggerScenarios":"Running AzureAIFoundry/Step01_Basics without AZURE_FOUNDRY_PROJECT_ENDPOINT. The throw at line 12 fires before SKAgentAsync, SKAgent_As_AFAgentAsync, and AFAgentAsync execute.","commonSituations":"Confusing AZURE_FOUNDRY_PROJECT_ENDPOINT with AZURE_OPENAI_ENDPOINT (different URL formats and resources); not having an Azure AI Foundry project provisioned; setting the OpenAI endpoint variable instead of the Foundry project endpoint.","solutions":["Set AZURE_FOUNDRY_PROJECT_ENDPOINT to your Foundry project URL (format: https://<project>-resource.services.ai.azure.com/api/projects/<project>)","Optionally set AZURE_FOUNDRY_PROJECT_DEPLOYMENT_NAME (defaults to gpt-4o)","Provision an Azure AI Foundry project and deploy a model in the Azure portal first","Ensure az login is current for AzureCliCredential"],"exampleFix":"// before\nvar azureEndpoint = Environment.GetEnvironmentVariable(\"AZURE_FOUNDRY_PROJECT_ENDPOINT\") ?? throw new InvalidOperationException(\"AZURE_FOUNDRY_PROJECT_ENDPOINT is not set.\");\n\n// after\nvar azureEndpoint = Environment.GetEnvironmentVariable(\"AZURE_FOUNDRY_PROJECT_ENDPOINT\")\n    ?? throw new InvalidOperationException(\n        \"AZURE_FOUNDRY_PROJECT_ENDPOINT is not set. \" +\n        \"Format: https://<project>-resource.services.ai.azure.com/api/projects/<project>\");","handlingStrategy":"validation","validationCode":"var endpoint = Environment.GetEnvironmentVariable(\"AZURE_FOUNDRY_PROJECT_ENDPOINT\");\nif (string.IsNullOrWhiteSpace(endpoint))\n{\n    Console.Error.WriteLine(\"AZURE_FOUNDRY_PROJECT_ENDPOINT is not set.\");\n    Console.Error.WriteLine(\"Format: https://<project>-resource.services.ai.azure.com/api/projects/<project>\");\n    return;\n}","typeGuard":"static bool IsFoundryEndpointConfigured() =>\n    !string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(\"AZURE_FOUNDRY_PROJECT_ENDPOINT\"));","tryCatchPattern":"try\n{\n    var endpoint = Environment.GetEnvironmentVariable(\"AZURE_FOUNDRY_PROJECT_ENDPOINT\")\n        ?? throw new InvalidOperationException(\"AZURE_FOUNDRY_PROJECT_ENDPOINT is not set.\");\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"AZURE_FOUNDRY_PROJECT_ENDPOINT\"))\n{\n    Console.Error.WriteLine(ex.Message);\n    Console.Error.WriteLine(\"Provision an Azure AI Foundry project first.\");\n    return;\n}","preventionTips":["Distinguish AZURE_FOUNDRY_PROJECT_ENDPOINT from AZURE_OPENAI_ENDPOINT — different URL formats and resources","Provision an Azure AI Foundry project and deploy a model before running any Foundry sample","Run az login to ensure AzureCliCredential can acquire a token for the Foundry project","Store the Foundry project endpoint in a shared env-var script used across all Step01-04 Foundry samples"],"tags":["configuration","csharp","azure-foundry","semantic-kernel","environment-variables","persistent-agents"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}