{"record":{"id":"2f758e3933c559cb","repo":"microsoft/aspire","slug":"microsoft-foundry-projects-are-not-supported-when-the-parent","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/FoundryExtensions.cs","lineNumber":268,"sourceCode":"                    timeout: default\n                    ));\n        builder.ApplicationBuilder.Services.AddHttpClient(nameof(FoundryLocalHealthCheck), client =>\n            client.Timeout = s_healthCheckTimeout);\n        builder.ApplicationBuilder.Services.AddHttpClient(nameof(LocalModelHealthCheck), client =>\n            client.Timeout = s_healthCheckTimeout);\n\n        builder.WithHealthCheck(healthCheckKey);\n\n        return builder;\n    }\n\n    internal static void ThrowIfProjectsConfiguredForLocal(IResourceBuilder<FoundryResource> builder, FoundryResource resource)\n    {\n        if (builder.ApplicationBuilder.Resources\n            .OfType<AzureCognitiveServicesProjectResource>()\n            .Any(project => ReferenceEquals(project.Parent, resource)))\n        {\n            throw new InvalidOperationException(LocalProjectsNotSupportedMessage);\n        }\n    }\n\n    /// <summary>\n    /// Assigns the specified roles to the given resource, granting it the necessary permissions\n    /// on the target Microsoft Foundry resource. This replaces the default role assignments for the resource.\n    /// </summary>\n    /// <param name=\"builder\">The resource to which the specified roles will be assigned.</param>\n    /// <param name=\"target\">The target Microsoft Foundry resource.</param>\n    /// <param name=\"roles\">The built-in Cognitive Services roles to be assigned.</param>\n    /// <returns>The updated <see cref=\"IResourceBuilder{T}\"/> with the applied role assignments.</returns>\n    /// <remarks>\n    /// <example>\n    /// Assigns the CognitiveServicesOpenAIContributor role to the 'Projects.Api' project.\n    /// <code lang=\"csharp\">\n    /// var builder = DistributedApplication.CreateBuilder(args);\n    ///\n    /// var aiFoundry = builder.AddFoundry(\"aiFoundry\");","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Foundry/FoundryExtensions.cs#L250-L286","documentation":"Foundry project (AzureCognitiveServicesProjectResource) child resources rely on Azure cloud behavior that Foundry Local emulation does not provide. When RunAsFoundryLocal is called on a parent Foundry resource that already has project resources attached, Aspire throws this InvalidOperationException because projects cannot run in local mode.","triggerScenarios":"Adding a project via .AddProject(...) on a Foundry resource and later calling .RunAsFoundryLocal() on the same Foundry resource builder.","commonSituations":"Enabling local development mode on an existing app model that already wires Foundry projects; experimenting with RunAsFoundryLocal without removing child projects.","solutions":["Remove the AzureCognitiveServicesProjectResource children before switching the parent to RunAsFoundryLocal","Keep the parent in Azure mode (don't call RunAsFoundryLocal) if projects are required","Move project deployments to a separate Foundry resource that stays in Azure mode"],"exampleFix":"// before\nvar foundry = builder.AddFoundry(\"foundry\")\n    .AddProject(\"proj\");\nfoundry.RunAsFoundryLocal(); // throws\n// after\nvar foundry = builder.AddFoundry(\"foundry\").AddProject(\"proj\"); // stays in Azure mode","handlingStrategy":"validation","validationCode":"bool hasProjects = builder.ApplicationBuilder.Resources\n    .OfType<AzureCognitiveServicesProjectResource>()\n    .Any(p => ReferenceEquals(p.Parent, foundry.Resource));\nif (hasProjects) { /* don't call RunAsFoundryLocal */ }","typeGuard":null,"tryCatchPattern":"try { foundry.RunAsFoundryLocal(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"not supported\")) { /* remove project children or stay in Azure mode */ }","preventionTips":["Decide Azure vs Foundry Local mode before adding child resources","Keep project deployments on resources that never run in local mode","Document the mode choice next to the Foundry resource configuration"],"tags":["azure-foundry","foundry-local","unsupported-operation"],"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"}