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

  1. Set AZURE_FOUNDRY_PROJECT_ENDPOINT to your Azure AI Foundry project URL
  2. Optionally set AZURE_FOUNDRY_PROJECT_DEPLOYMENT_NAME (defaults to gpt-4o)
  3. Confirm the Foundry project has a deployed model that supports function calling
  4. 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

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


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/45f647eca2a80b42. Report an issue: GitHub.