{"record":{"id":"97e484d9ccc29307","repo":"microsoft/aspire","slug":"invalid-container-image-format","errorCode":null,"errorMessage":"Invalid container image format","messagePattern":"Invalid container image format","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/Publishing/DockerContainerRuntime.cs","lineNumber":68,"sourceCode":"            {\n                arguments += $\" --builder \\\"{builderName}\\\"\";\n            }\n\n            // Add platform support if specified\n            if (options?.TargetPlatform is not null)\n            {\n                arguments += $\" --platform \\\"{options.TargetPlatform.Value.ToRuntimePlatformString()}\\\"\";\n            }\n\n            // Add output format support if specified\n            if (options?.ImageFormat is not null || !string.IsNullOrEmpty(options?.OutputPath))\n            {\n                var outputType = options?.ImageFormat switch\n                {\n                    ContainerImageFormat.Oci => \"type=oci\",\n                    ContainerImageFormat.Docker => \"type=docker\",\n                    null => \"type=docker\",\n                    _ => throw new ArgumentOutOfRangeException(nameof(options), options.ImageFormat, \"Invalid container image format\")\n                };\n\n                if (!string.IsNullOrEmpty(options?.OutputPath))\n                {\n                    var archivePath = ResourceExtensions.GetContainerImageArchivePath(options.OutputPath, imageName);\n                    outputType += $\",dest={archivePath}\";\n                }\n\n                arguments += $\" --output \\\"{outputType}\\\"\";\n            }\n\n            // Add build arguments if specified\n            arguments += BuildArgumentsString(buildArguments);\n\n            // Add build secrets if specified\n            arguments += BuildSecretsString(buildSecrets);\n\n            // Add stage if specified","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/Publishing/DockerContainerRuntime.cs#L50-L86","documentation":"The image output type is selected with a switch expression over ContainerImageFormat that handles Oci, Docker, and null (defaulting to docker); any other enum value falls into the throw arm of ArgumentOutOfRangeException. Because ContainerImageFormat only has those members in practice, this is an internal invariant guard against unexpected or out-of-range values.","triggerScenarios":"Passing an ImageFormat value to BuildImageAsync that is not Oci, Docker, or null — e.g. an invalid cast from an int to ContainerImageFormat producing an undefined enum value, or a future enum member added upstream without updating this switch.","commonSituations":"Parsing a format string from configuration into the enum without validation ((ContainerImageFormat)42); deserializing enum values from JSON; version skew between an app and a newer Aspire package that added a format.","solutions":["Pass a valid ContainerImageFormat value (Oci, Docker) or null instead of an arbitrary cast.","Validate config-driven format strings with Enum.TryParse before assigning ImageFormat.","Upgrade the Aspire.Hosting package if the value came from a newer version's enum."],"exampleFix":"// before\nvar format = (ContainerImageFormat)int.Parse(config[\"format\"]);\n// after\nif (!Enum.TryParse<ContainerImageFormat>(config[\"format\"], out var format))\n{\n    throw new InvalidOperationException($\"Unknown container image format '{config[\"format\"]}'\");\n}","handlingStrategy":"validation","validationCode":"if (format is not null && format is not ContainerImageFormat.Oci and not ContainerImageFormat.Docker)\n{\n    throw new ArgumentException($\"Unsupported image format: {format}\", nameof(format));\n}","typeGuard":"bool IsKnownFormat(ContainerImageFormat? f) => f is null or ContainerImageFormat.Oci or ContainerImageFormat.Docker;","tryCatchPattern":"try\n{\n    await runtime.BuildImageAsync(ctx, dockerfile, options, args, secrets, stage, ct);\n}\ncatch (ArgumentOutOfRangeException ex)\n{\n    logger.LogError(ex, \"Unknown ContainerImageFormat value {Value}.\", ex.ActualValue);\n}","preventionTips":["Never cast raw ints to ContainerImageFormat; use Enum.TryParse.","Assign ImageFormat only from known constants or parsed-and-validated config.","Avoid boxing/deserializing enum values without validation."],"tags":["docker","image-build","enum","argument-out-of-range"],"backgroundTag":"invalid-enum-value","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"}