{"record":{"id":"9b99eeb8c798f6bd","repo":"microsoft/semantic-kernel","slug":"azure-foundry-project-endpoint-is-not-set-9b99ee","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/Step04_CodeInterpreter/Program.cs","lineNumber":15,"sourceCode":"﻿// Copyright (c) Microsoft. All rights reserved.\n\nusing System.Text;\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;\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 = \"Create a python code file using the code interpreter tool with a code ready to determine the values in the Fibonacci sequence that are less then the value of 101\";\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(deploymentName, tools: [new CodeInterpreterToolDefinition()]);\n\n    AzureAIAgent agent = new(definition, azureAgentClient);","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/AgentFrameworkMigration/AzureAIFoundry/Step04_CodeInterpreter/Program.cs#L1-L33","documentation":"The Azure AI Foundry CodeInterpreter migration sample throws InvalidOperationException when AZURE_FOUNDRY_PROJECT_ENDPOINT is null. This sample demonstrates the code interpreter tool with persistent agents for generating and running Python code. The Foundry project endpoint is required to provision the agent with code interpreter capabilities.","triggerScenarios":"Running AzureAIFoundry/Step04_CodeInterpreter without AZURE_FOUNDRY_PROJECT_ENDPOINT. The throw at line 15 fires before the code interpreter tool is attached or the Fibonacci prompt is sent.","commonSituations":"The Foundry project does not have code interpreter enabled; confusing the standard Azure OpenAI endpoint with the Foundry project endpoint; the model deployed in the project does not support code interpreter.","solutions":["Set AZURE_FOUNDRY_PROJECT_ENDPOINT to your Azure AI Foundry project URL","Optionally set AZURE_FOUNDRY_PROJECT_DEPLOYMENT_NAME (defaults to gpt-4o)","Ensure the Foundry project has code interpreter enabled and a compatible model deployed","Run az login 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\");\nif (string.IsNullOrWhiteSpace(azureEndpoint))\n    throw new InvalidOperationException(\n        \"AZURE_FOUNDRY_PROJECT_ENDPOINT is not set. Provision a Foundry project first.\");","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 code interpreter 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":["Ensure the Foundry project has code interpreter enabled before running this sample","Confirm the deployed model supports code interpreter capabilities","Run az login before executing","Distinguish Foundry project endpoint from Azure OpenAI resource endpoint"],"tags":["configuration","csharp","azure-foundry","semantic-kernel","environment-variables","code-interpreter","persistent-agents"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}