microsoft/semantic-kernel · error · InvalidOperationException
AZURE_FOUNDRY_PROJECT_ENDPOINT is not set.
Error message
AZURE_FOUNDRY_PROJECT_ENDPOINT is not set.
What it means
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.
Source
Thrown at dotnet/samples/AgentFrameworkMigration/AzureAIFoundry/Step02_ToolCall/Program.cs:14
// Copyright (c) Microsoft. All rights reserved.
using System.ComponentModel;
using Azure.AI.Agents.Persistent;
using Azure.AI.Projects;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents.AzureAI;
#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.
var azureEndpoint = Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("AZURE_FOUNDRY_PROJECT_ENDPOINT is not set.");
var deploymentName = System.Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_DEPLOYMENT_NAME") ?? "gpt-4o";
var userInput = "What is the weather like in Amsterdam?";
Console.WriteLine($"User Input: {userInput}");
[KernelFunction]
[Description("Get the weather for a given location.")]
static string GetWeather([Description("The location to get the weather for.")] string location)
=> $"The weather in {location} is cloudy with a high of 15°C.";
await SKAgentAsync();
await SKAgent_As_AFAgentAsync();
await AFAgentAsync();
async Task SKAgentAsync()
{
Console.WriteLine("\n=== SK Agent ===\n");
View on GitHub (pinned to c028a0c7dc)
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
Example fix
// before
var azureEndpoint = Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("AZURE_FOUNDRY_PROJECT_ENDPOINT is not set.");
// after
var azureEndpoint = Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_ENDPOINT");
if (string.IsNullOrWhiteSpace(azureEndpoint))
throw new InvalidOperationException(
"AZURE_FOUNDRY_PROJECT_ENDPOINT is required. See README.md for setup instructions."); Defensive patterns
Strategy: validation
Validate before calling
var endpoint = Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_ENDPOINT");
if (string.IsNullOrWhiteSpace(endpoint))
{
Console.Error.WriteLine("AZURE_FOUNDRY_PROJECT_ENDPOINT is required for tool-calling samples.");
return;
} Type guard
static bool IsFoundryEndpointConfigured() =>
!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_ENDPOINT")); Try / catch
try
{
var endpoint = Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_ENDPOINT")
?? throw new InvalidOperationException("AZURE_FOUNDRY_PROJECT_ENDPOINT is not set.");
}
catch (InvalidOperationException ex) when (ex.Message.Contains("AZURE_FOUNDRY_PROJECT_ENDPOINT"))
{
Console.Error.WriteLine(ex.Message);
return;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- AZURE_FOUNDRY_PROJECT_ENDPOINT is not set.
- AZURE_FOUNDRY_PROJECT_ENDPOINT is not set.
- AZURE_FOUNDRY_PROJECT_ENDPOINT is not set.
- AZURE_OPENAI_ENDPOINT is not set.
- AZURE_OPENAI_ENDPOINT is not set.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/45f647eca2a80b42.
Report an issue: GitHub.