{"record":{"id":"45f647eca2a80b42","repo":"microsoft/semantic-kernel","slug":"azure-foundry-project-endpoint-is-not-set-45f647","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/Step02_ToolCall/Program.cs","lineNumber":14,"sourceCode":"﻿// Copyright (c) Microsoft. All rights reserved.\n\nusing System.ComponentModel;\nusing Azure.AI.Agents.Persistent;\nusing Azure.AI.Projects;\nusing Azure.Identity;\nusing Microsoft.Agents.AI;\nusing Microsoft.Extensions.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 = \"What is the weather like in Amsterdam?\";\n\nConsole.WriteLine($\"User Input: {userInput}\");\n\n[KernelFunction]\n[Description(\"Get the weather for a given location.\")]\nstatic string GetWeather([Description(\"The location to get the weather for.\")] string location)\n    => $\"The weather in {location} is cloudy with a high of 15°C.\";\n\nawait SKAgentAsync();\nawait SKAgent_As_AFAgentAsync();\nawait AFAgentAsync();\n\nasync Task SKAgentAsync()\n{\n    Console.WriteLine(\"\\n=== SK Agent ===\\n\");\n","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/AgentFrameworkMigration/AzureAIFoundry/Step02_ToolCall/Program.cs#L1-L32","documentation":"The Azure AI Foundry ToolCall migration sample throws InvalidOperationException when AZURE_FOUNDRY_PROJECT_ENDPOINT is unset. This sample demonstrates function/tool calling (GetWeather) with both SK and AF using cloud-hosted persistent agents. The Foundry project endpoint is required to create the PersistentAgentsClient that backs the agents.","triggerScenarios":"Running AzureAIFoundry/Step02_ToolCall without AZURE_FOUNDRY_PROJECT_ENDPOINT. The throw at line 14 fires before the KernelFunction GetWeather is registered or any agent is invoked.","commonSituations":"Running the tool-call sample without the Foundry project; mistaking the OpenAI endpoint for the Foundry project endpoint; the Foundry project was deleted or the endpoint URL changed.","solutions":["Set AZURE_FOUNDRY_PROJECT_ENDPOINT to your Azure AI Foundry project URL","Optionally set AZURE_FOUNDRY_PROJECT_DEPLOYMENT_NAME (defaults to gpt-4o)","Confirm the Foundry project has a deployed model that supports function calling","Run az login to ensure AzureCliCredential can obtain a token"],"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\");\nif (string.IsNullOrWhiteSpace(azureEndpoint))\n    throw new InvalidOperationException(\n        \"AZURE_FOUNDRY_PROJECT_ENDPOINT is required. See README.md for setup instructions.\");","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 required for tool-calling samples.\");\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    return;\n}","preventionTips":["Verify the Foundry project has a deployed model that supports function calling","Do not confuse the Foundry project endpoint with the Azure OpenAI resource endpoint","Use a shared env-var setup script for all AzureAIFoundry samples","Confirm az login is valid before running"],"tags":["configuration","csharp","azure-foundry","semantic-kernel","environment-variables","tool-calling","persistent-agents"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}