{"record":{"id":"142c4a41623a442f","repo":"microsoft/aspire","slug":"invalid-container-image-format-resourcecontainerimagemanager","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/ResourceContainerImageManager.cs","lineNumber":356,"sourceCode":"\n        if (GetLocalRegistryName(containerRuntime) is string localRegistry)\n        {\n            arguments += $\" /p:LocalRegistry=\\\"{localRegistry}\\\"\";\n        }\n\n        // Add additional arguments based on options\n        if (!string.IsNullOrEmpty(options.OutputPath))\n        {\n            arguments += $\" /p:ContainerArchiveOutputPath=\\\"{options.OutputPath}\\\"\";\n        }\n\n        if (options.ImageFormat is not null)\n        {\n            var format = options.ImageFormat.Value switch\n            {\n                ContainerImageFormat.Docker => \"Docker\",\n                ContainerImageFormat.Oci => \"OCI\",\n                _ => throw new ArgumentOutOfRangeException(nameof(options), options.ImageFormat, \"Invalid container image format\")\n            };\n            arguments += $\" /p:ContainerImageFormat=\\\"{format}\\\"\";\n        }\n\n        if (options.TargetPlatform is not null)\n        {\n            // Use the appropriate MSBuild properties based on the number of RIDs\n            var runtimeIds = options.TargetPlatform.Value.ToMSBuildRuntimeIdentifierString();\n            var ridArray = runtimeIds.Split(';');\n\n            if (ridArray.Length == 1)\n            {\n                // Single platform - use RuntimeIdentifier/ContainerRuntimeIdentifier\n                arguments += $\" /p:RuntimeIdentifier=\\\"{ridArray[0]}\\\"\";\n                arguments += $\" /p:ContainerRuntimeIdentifier=\\\"{ridArray[0]}\\\"\";\n            }\n            else\n            {","sourceCodeStart":338,"sourceCodeEnd":374,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/Publishing/ResourceContainerImageManager.cs#L338-L374","documentation":"When translating ContainerImageFormat options into MSBuild properties for 'dotnet publish /t:PublishContainer', the switch only maps Docker and OCI. Any other value falls into the discard arm and throws ArgumentOutOfRangeException named on options.ImageFormat with message 'Invalid container image format'.","triggerScenarios":"Passing an undefined/out-of-range ContainerImageFormat enum value in ContainerBuildOptions.ImageFormat (e.g. an invalid cast of an int to the enum, or a value from a newer/older assembly version of the enum).","commonSituations":"Deserializing build options from configuration or JSON where an int is cast blindly to ContainerImageFormat; version mismatch between packages defining the enum; hand-written code passing (ContainerImageFormat)99.","solutions":["Only pass ContainerImageFormat.Docker or ContainerImageFormat.Oci.","Validate/parse the value with Enum.IsEnumDefined before assigning ImageFormat.","Align package versions so the enum definition matches across projects.","Leave ImageFormat null to use the SDK default."],"exampleFix":"// before\nvar options = new ContainerBuildOptions { ImageFormat = (ContainerImageFormat)42 };\n\n// after\nvar fmt = (ContainerImageFormat)42;\nvar options = new ContainerBuildOptions\n{\n    ImageFormat = Enum.IsEnumDefined(fmt) && fmt != 0 ? fmt : null\n};","handlingStrategy":"validation","validationCode":"if (options.ImageFormat is { } fmt && !Enum.IsEnumDefined(fmt))\n{\n    throw new ArgumentException($\"Unknown ContainerImageFormat: {fmt}\");\n}","typeGuard":"static bool IsValidImageFormat(ContainerImageFormat? f) => f is null || f is ContainerImageFormat.Docker or ContainerImageFormat.Oci;","tryCatchPattern":"try { await manager.BuildImageAsync(resource, opts, ct); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName is \"options\" && ex.Message.Contains(\"Invalid container image format\"))\n{\n    // reset ImageFormat to null (SDK default) and retry\n}","preventionTips":["Never cast raw ints to ContainerImageFormat without Enum.IsEnumDefined.","Keep package versions aligned so enum definitions match.","Leave ImageFormat null unless a specific format is required.","Parse config values with Enum.TryParse<ContainerImageFormat>."],"tags":["enum","argument-out-of-range","container-image-format"],"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"}