{"record":{"id":"c3f565240b79dacb","repo":"microsoft/aspire","slug":"model-version-and-format-must-be-omitted-when-using-a-c3f565","errorCode":null,"errorMessage":"Model version and format must be omitted when using a FoundryModel.","messagePattern":"Model version and format must be omitted when using a FoundryModel\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Foundry/Project/ProjectBuilderExtension.cs","lineNumber":308,"sourceCode":"    /// <summary>\n    /// Adds a model deployment to the parent Microsoft Foundry resource.\n    /// </summary>\n    [AspireExport(\"addModelDeployment\")]\n    internal static IResourceBuilder<FoundryDeploymentResource> AddModelDeploymentForPolyglot(\n        this IResourceBuilder<AzureCognitiveServicesProjectResource> builder,\n        [ResourceName] string name,\n        [AspireUnion(typeof(FoundryModel), typeof(string))] object model,\n        string? modelVersion = null,\n        string? format = null)\n    {\n        ArgumentNullException.ThrowIfNull(builder);\n        ArgumentNullException.ThrowIfNull(model);\n        ArgumentException.ThrowIfNullOrEmpty(name);\n\n        return model switch\n        {\n            FoundryModel foundryModel when modelVersion is null && format is null => builder.AddModelDeployment(name, foundryModel),\n            FoundryModel => throw new ArgumentException(\"Model version and format must be omitted when using a FoundryModel.\", nameof(modelVersion)),\n            string modelName when modelVersion is not null && format is not null => builder.AddModelDeployment(name, modelName, modelVersion, format),\n            string => throw new ArgumentException(\"Model version and format are required when the model is provided as a string.\", nameof(modelVersion)),\n            _ => throw new ArgumentException(\"Model must be a FoundryModel or a string model name.\", nameof(model))\n        };\n    }\n\n    /// <summary>\n    /// Adds a model deployment to the parent Microsoft Foundry resource of the Microsoft Foundry project.\n    /// </summary>\n    [AspireExportIgnore(Reason = \"Polyglot AppHosts use the internal addModelDeployment dispatcher export.\")]\n    public static IResourceBuilder<FoundryDeploymentResource> AddModelDeployment(\n        this IResourceBuilder<AzureCognitiveServicesProjectResource> builder,\n        [ResourceName] string name,\n        string modelName,\n        string modelVersion,\n        string format)\n    {\n        ArgumentNullException.ThrowIfNull(builder);","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Foundry/Project/ProjectBuilderExtension.cs#L290-L326","documentation":"AddModelDeploymentForPolyglot accepts either a FoundryModel or a string model name. When a FoundryModel is supplied, modelVersion and format must be null because the model object already carries them; passing either throws this ArgumentException.","triggerScenarios":"Calling AddModelDeploymentForPolyglot with a FoundryModel instance while also supplying a non-null modelVersion or format argument.","commonSituations":"Translating older string-based calls to FoundryModel without removing the now-redundant version/format arguments; copying a string-model call and only swapping the model argument for a FoundryModel.","solutions":["Remove the modelVersion and format arguments when passing a FoundryModel","If you need an explicit version/format, pass the model name as a string with both modelVersion and format instead","Set modelVersion and format to null in the calling code when a FoundryModel is used"],"exampleFix":"// before\nproject.AddModelDeploymentForPolyglot(\"gpt-4o\", FoundryModel.FromName(\"gpt-4o\"), \"2024-11-20\", \"OpenAI\");\n\n// after\nproject.AddModelDeploymentForPolyglot(\"gpt-4o\", FoundryModel.FromName(\"gpt-4o\"));","handlingStrategy":"validation","validationCode":"if (model is FoundryModel && (modelVersion is not null || format is not null))\n{\n    modelVersion = null;\n    format = null;\n}\nproject.AddModelDeploymentForPolyglot(name, model, modelVersion, format);","typeGuard":null,"tryCatchPattern":"try { project.AddModelDeploymentForPolyglot(name, model, modelVersion, format); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"must be omitted\"))\n{\n    // Retry without version/format when a FoundryModel was supplied.\n}","preventionTips":["When using FoundryModel, never pass modelVersion or format","Decide up front whether the model is a FoundryModel or a string name+version+format","Document the two call shapes in shared AppHost helpers"],"tags":["csharp","aspire","azure","conflicting-arguments"],"backgroundTag":"conflicting-config-options","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"}