{"record":{"id":"cfc01e3a3f0426c6","repo":"microsoft/aspire","slug":"model-version-and-format-are-required-when-the-model-is","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/FoundryExtensions.cs","lineNumber":107,"sourceCode":"    /// </summary>\n    [AspireExport(\"addDeployment\")]\n    internal static IResourceBuilder<FoundryDeploymentResource> AddDeploymentForPolyglot(\n        this IResourceBuilder<FoundryResource> 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.AddDeployment(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.AddDeployment(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 and returns a Microsoft Foundry Deployment resource to the application model using a <see cref=\"FoundryModel\"/>.\n    /// </summary>\n    /// <param name=\"builder\">The Microsoft Foundry resource builder.</param>\n    /// <param name=\"name\">The name of the Microsoft Foundry Deployment resource.</param>\n    /// <param name=\"model\">The model descriptor, using the <see cref=\"FoundryModel\"/> class like so: <code lang=\"csharp\">aiFoundry.AddDeployment(name: \"chat\", model: FoundryModel.OpenAI.Gpt5Mini)</code></param>\n    /// <returns>A reference to the <see cref=\"IResourceBuilder{T}\"/>.</returns>\n    /// <remarks>\n    /// <example>\n    /// Create a deployment for the OpenAI GTP-5-mini model:\n    /// <code lang=\"csharp\">\n    /// var builder = DistributedApplication.CreateBuilder(args);\n    ///\n    /// var aiFoundry = builder.AddFoundry(\"aiFoundry\");","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Foundry/FoundryExtensions.cs#L89-L125","documentation":"When the model argument is a plain string model name, AddDeploymentForPolyglot requires both modelVersion and format to be supplied, because a bare name alone cannot form a valid deployment definition. Omitting either throws this ArgumentException.","triggerScenarios":"Calling builder.AddDeploymentForPolyglot(name, \"gpt-4o\") with modelVersion and/or format null.","commonSituations":"Assuming the string overload behaves like the FoundryModel overload; forgetting to pass the model format (e.g. \"OpenAI\") alongside the model name and version.","solutions":["Pass both modelVersion and format when using a string model name","Alternatively use a FoundryModel instance (created via the Foundry resource) so version/format are implied"],"exampleFix":"// before\nbuilder.AddDeploymentForPolyglot(\"deploy\", \"gpt-4o\");\n// after\nbuilder.AddDeploymentForPolyglot(\"deploy\", \"gpt-4o\", \"2024-11-20\", \"OpenAI\");","handlingStrategy":"validation","validationCode":"if (model is string && (modelVersion is null || format is null))\n    throw new ArgumentException(\"String model names require both modelVersion and format.\");","typeGuard":null,"tryCatchPattern":"try { builder.AddDeploymentForPolyglot(name, modelName, version, format); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"are required\")) { /* supply version and format */ }","preventionTips":["Always pass version and format when using string model names","Consider constructing a FoundryModel to avoid remembering the argument rules","Keep model name/version/format triples in a shared constant or config object"],"tags":["azure-foundry","arguments","aspire-hosting"],"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"}