{"record":{"id":"4b2c4c5641af390d","repo":"microsoft/aspire","slug":"microsoft-foundry-projects-are-not-supported-when-the-parent-4b2c4c","errorCode":null,"errorMessage":"Microsoft Foundry projects are not supported when the parent Foundry resource is configured with RunAsFoundryLocal().","messagePattern":"Microsoft Foundry projects are not supported when the parent Foundry resource is configured with RunAsFoundryLocal\\(\\)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Foundry/Project/ProjectBuilderExtension.cs","lineNumber":47,"sourceCode":"    /// <summary>\n    /// Adds a Microsoft Foundry project resource to the application model.\n    ///\n    /// This will also attach the project as a deployment target for agents.\n    /// </summary>\n    /// <param name=\"builder\">The <see cref=\"IResourceBuilder{T}\"/> for the parent Microsoft Foundry account resource.</param>\n    /// <param name=\"name\">The name of the Microsoft Foundry project resource.</param>\n    /// <returns>A reference to the <see cref=\"IResourceBuilder{T}\"/> for the Microsoft Foundry project resource.</returns>\n    /// <ats-returns>The resource builder.</ats-returns>\n    [AspireExport]\n    public static IResourceBuilder<AzureCognitiveServicesProjectResource> AddProject(\n        this IResourceBuilder<FoundryResource> builder,\n        [ResourceName] string name)\n    {\n        ArgumentNullException.ThrowIfNull(builder);\n        ArgumentException.ThrowIfNullOrEmpty(name);\n        if (builder.Resource.IsEmulator)\n        {\n            throw new InvalidOperationException(FoundryExtensions.LocalProjectsNotSupportedMessage);\n        }\n\n        builder.ApplicationBuilder.Services.Configure<AzureProvisioningOptions>(o => o.SupportsTargetedRoleAssignments = true);\n\n        var project = builder.ApplicationBuilder.AddResource(new AzureCognitiveServicesProjectResource(name, ConfigureInfrastructure, builder.Resource));\n        if (builder.ApplicationBuilder.ExecutionContext.IsPublishMode)\n        {\n            project.Resource.DefaultContainerRegistry = CreateDefaultRegistry(builder.ApplicationBuilder, $\"{name}-acr\");\n        }\n\n        return project;\n    }\n\n    /// <summary>\n    /// Adds a reference to a Microsoft Foundry project resource to the destination resource.\n    /// </summary>\n    /// <remarks>This overload is not available in polyglot app hosts. Use the standard <c>WithReference</c> overload instead.</remarks>\n    [AspireExportIgnore(Reason = \"The standard WithReference export already covers this polyglot scenario.\")]","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Foundry/Project/ProjectBuilderExtension.cs#L29-L65","documentation":"When the parent Foundry resource is configured with RunAsFoundryLocal(), it runs the Foundry Local emulator, which cannot host Foundry projects. AddProject checks builder.Resource.IsEmulator and throws this InvalidOperationException (FoundryExtensions.LocalProjectsNotSupportedMessage) when a project resource is added in that mode.","triggerScenarios":"Calling foundry.AddFoundryLocal(...) / RunAsFoundryLocal() on the parent Foundry resource and then calling foundry.AddProject(\"name\") to add a project resource to it.","commonSituations":"Local development configured for Foundry Local while sample code also adds projects; mixing emulator-based local setups with project-based deployment models in one app model.","solutions":["Remove RunAsFoundryLocal() so the Foundry resource provisions real projects in Azure.","Only call AddProject when the parent Foundry resource is not running as Foundry Local (guard on builder.Resource.IsEmulator or execution context).","Use Foundry Local's own APIs/models directly instead of Foundry projects for the emulated scenario."],"exampleFix":"// before\nvar foundry = builder.AddAzureFoundry(\"foundry\").RunAsFoundryLocal();\nfoundry.AddProject(\"agent-project\"); // throws\n\n// after\nvar foundry = builder.AddAzureFoundry(\"foundry\"); // no RunAsFoundryLocal\nfoundry.AddProject(\"agent-project\");","handlingStrategy":"validation","validationCode":"if (!foundry.Resource.IsEmulator)\n    foundry.AddProject(\"agent-project\");","typeGuard":null,"tryCatchPattern":"try { foundry.AddProject(name); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"RunAsFoundryLocal\")) { /* switch to real provisioning or use Foundry Local APIs */ }","preventionTips":["Decide up front whether the app targets Foundry Local or Azure Foundry projects; they are mutually exclusive.","Gate AddProject calls behind the parent resource's IsEmulator flag.","Avoid sharing one Foundry resource builder between local-emulator and project-based code paths."],"tags":["azure-ai-foundry","foundry-local","emulator","projects"],"backgroundTag":"unsupported-operation","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}