microsoft/aspire · error · ArgumentException

Model version and format are required when the model is…

Error message

Model version and format are required when the model is provided as a string.

What it means

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.

Solutions

  1. Pass both modelVersion and format when using a string model name
  2. Alternatively use a FoundryModel instance (created via the Foundry resource) so version/format are implied

Example fix

// before
builder.AddDeploymentForPolyglot("deploy", "gpt-4o");
// after
builder.AddDeploymentForPolyglot("deploy", "gpt-4o", "2024-11-20", "OpenAI");
Defensive patterns

Strategy: validation

Validate before calling

if (model is string && (modelVersion is null || format is null))
    throw new ArgumentException("String model names require both modelVersion and format.");

Try / catch

try { builder.AddDeploymentForPolyglot(name, modelName, version, format); }
catch (ArgumentException ex) when (ex.Message.Contains("are required")) { /* supply version and format */ }

Prevention

When it happens

Trigger: Calling builder.AddDeploymentForPolyglot(name, "gpt-4o") with modelVersion and/or format null.

Common situations: Assuming the string overload behaves like the FoundryModel overload; forgetting to pass the model format (e.g. "OpenAI") alongside the model name and version.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/cfc01e3a3f0426c6. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.Foundry/FoundryExtensions.cs:107

    /// </summary>
    [AspireExport("addDeployment")]
    internal static IResourceBuilder<FoundryDeploymentResource> AddDeploymentForPolyglot(
        this IResourceBuilder<FoundryResource> builder,
        [ResourceName] string name,
        [AspireUnion(typeof(FoundryModel), typeof(string))] object model,
        string? modelVersion = null,
        string? format = null)
    {
        ArgumentNullException.ThrowIfNull(builder);
        ArgumentNullException.ThrowIfNull(model);
        ArgumentException.ThrowIfNullOrEmpty(name);

        return model switch
        {
            FoundryModel foundryModel when modelVersion is null && format is null => builder.AddDeployment(name, foundryModel),
            FoundryModel => throw new ArgumentException("Model version and format must be omitted when using a FoundryModel.", nameof(modelVersion)),
            string modelName when modelVersion is not null && format is not null => builder.AddDeployment(name, modelName, modelVersion, format),
            string => throw new ArgumentException("Model version and format are required when the model is provided as a string.", nameof(modelVersion)),
            _ => throw new ArgumentException("Model must be a FoundryModel or a string model name.", nameof(model))
        };
    }

    /// <summary>
    /// Adds and returns a Microsoft Foundry Deployment resource to the application model using a <see cref="FoundryModel"/>.
    /// </summary>
    /// <param name="builder">The Microsoft Foundry resource builder.</param>
    /// <param name="name">The name of the Microsoft Foundry Deployment resource.</param>
    /// <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>
    /// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
    /// <remarks>
    /// <example>
    /// Create a deployment for the OpenAI GTP-5-mini model:
    /// <code lang="csharp">
    /// var builder = DistributedApplication.CreateBuilder(args);
    ///
    /// var aiFoundry = builder.AddFoundry("aiFoundry");

View on GitHub (pinned to 25830f84bd)