{"record":{"id":"74a2a8487a017de2","repo":"microsoft/aspire","slug":"model-version-and-format-are-required-when-the-model-is-74a2a8","errorCode":null,"errorMessage":"Model version and format are required when the model is provided as a string.","messagePattern":"Model version and format are required when the model is provided as a string\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Foundry/Project/ProjectBuilderExtension.cs","lineNumber":310,"sourceCode":"    /// </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);\n        ArgumentException.ThrowIfNullOrEmpty(name);\n        return builder.ApplicationBuilder.CreateResourceBuilder(builder.Resource.Parent).AddDeployment(name, modelName, modelVersion, format);","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Foundry/Project/ProjectBuilderExtension.cs#L292-L328","documentation":"AddModelDeploymentForPolyglot requires that when the model is given as a plain string, both modelVersion and format are also supplied, since a bare name does not carry them. If either is null, the switch throws this ArgumentException for the string case.","triggerScenarios":"Calling AddModelDeploymentForPolyglot with a string model name but leaving modelVersion or format (or both) null.","commonSituations":"Porting code from a FoundryModel-based call to a string-based one without adding version and format; assuming defaults exist for string model names; partially filling only one of the two arguments.","solutions":["Supply both modelVersion and format when the model is a string name","Use a FoundryModel instance instead of a string so version and format are embedded","Fill in the missing argument (e.g. the format) that was left null"],"exampleFix":"// before\nproject.AddModelDeploymentForPolyglot(\"gpt-4o\", \"gpt-4o\", \"2024-11-20\", null);\n\n// after\nproject.AddModelDeploymentForPolyglot(\"gpt-4o\", \"gpt-4o\", \"2024-11-20\", \"OpenAI\");","handlingStrategy":"validation","validationCode":"if (model is string && (modelVersion is null || format is null))\n{\n    throw new InvalidOperationException(\"string models require both modelVersion and format.\");\n}\nproject.AddModelDeploymentForPolyglot(name, model, modelVersion, format);","typeGuard":null,"tryCatchPattern":"try { project.AddModelDeploymentForPolyglot(name, model, modelVersion, format); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"are required\"))\n{\n    // Supply version/format or switch to FoundryModel.\n}","preventionTips":["Always pass both modelVersion and format for string model names","Prefer FoundryModel instances which embed version and format","Validate config-driven model entries for version and format before building"],"tags":["csharp","aspire","azure","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}