{"record":{"id":"4828921b4c6489d3","repo":"dotnet/machinelearning","slug":"invalid-image-resizing-mode-value","errorCode":null,"errorMessage":"Invalid image resizing mode value","messagePattern":"Invalid image resizing mode value","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.ImageAnalytics/ImageResizer.cs","lineNumber":323,"sourceCode":"                        }\n\n                        dst = src.CloneWithResizing(\n                                info.ImageWidth,\n                                info.ImageHeight,\n                                info.Resizing switch\n                                {\n                                    ImageResizingEstimator.ResizingKind.IsoPad => ImageResizeMode.Pad,\n                                    ImageResizingEstimator.ResizingKind.IsoCrop =>\n                                        info.Anchor switch\n                                        {\n                                            ImageResizingEstimator.Anchor.Top => ImageResizeMode.CropAnchorTop,\n                                            ImageResizingEstimator.Anchor.Bottom => ImageResizeMode.CropAnchorBottom,\n                                            ImageResizingEstimator.Anchor.Left => ImageResizeMode.CropAnchorLeft,\n                                            ImageResizingEstimator.Anchor.Right => ImageResizeMode.CropAnchorRight,\n                                            _ => ImageResizeMode.CropAnchorCentral\n                                        },\n                                    ImageResizingEstimator.ResizingKind.Fill => ImageResizeMode.Fill,\n                                    _ => throw new InvalidOperationException($\"Invalid image resizing mode value\")\n                                });\n\n                        dst.Tag = src.Tag;\n                        Contracts.Assert(dst.Width == info.ImageWidth && dst.Height == info.ImageHeight);\n                    };\n\n                return del;\n            }\n        }\n    }\n\n    /// <summary>\n    /// <see cref=\"IEstimator{TTransformer}\"/> for the <see cref=\"ImageResizingTransformer\"/>.\n    /// </summary>\n    /// <remarks>\n    /// <format type=\"text/markdown\"><![CDATA[\n    ///\n    /// ###  Estimator Characteristics","sourceCodeStart":305,"sourceCodeEnd":341,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.ImageAnalytics/ImageResizer.cs#L305-L341","documentation":"ImageResizer maps the estimator's ResizingKind enum (IsoCrop with anchors, or Fill) onto native resize modes. The switch covers ResizingKind.IsoCrop and ResizingKind.Fill; any other/unrecognized value hits the discard arm and throws InvalidOperationException. This normally indicates a value outside the defined enum range was used.","triggerScenarios":"Passing an out-of-range or undefined ImageResizingEstimator.ResizingKind value (e.g. a cast int, a value from a newer/older assembly version) into the ImageResizingEstimator/ImageResizingTransformer options so MakeGetter's switch reaches its default arm.","commonSituations":"Deserializing resize options from JSON/config where the enum value was stored as a raw integer or renamed between ML.NET versions; assembly version mismatches between Microsoft.ML packages.","solutions":["Use only ImageResizingEstimator.ResizingKind.IsoCrop or .Fill","Validate/deserialize config into the enum with Enum.TryParse before constructing the estimator","Align Microsoft.ML package versions so enum definitions match at compile and run time"],"exampleFix":"// before\nvar est = new ImageResizingEstimator(env, columns, (ResizingKind)7, ...);\n// after\nif (!Enum.TryParse<ResizingKind>(resizeKindText, out var kind) ||\n    (kind != ResizingKind.IsoCrop && kind != ResizingKind.Fill))\n    throw new ArgumentException($\"Unsupported resizing kind: {resizeKindText}\");\nvar est = new ImageResizingEstimator(env, columns, kind, ...);","handlingStrategy":"type-guard","validationCode":"if (!Enum.IsDefined(typeof(ImageResizingEstimator.ResizingKind), resizingKind))\n    throw new ArgumentException($\"Unknown resizing kind: {resizingKind}\");","typeGuard":"bool IsValidResizingKind(object v) => v is ImageResizingEstimator.ResizingKind k && (k == ImageResizingEstimator.ResizingKind.IsoCrop || k == ImageResizingEstimator.ResizingKind.Fill);","tryCatchPattern":"try\n{\n    BuildResizer(options);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"resizing mode\"))\n{\n    logger.LogError(ex, \"Bad ResizingKind {Kind} in config\", options.ResizingKind);\n}","preventionTips":["Never cast raw ints to the enum from config; use Enum.TryParse + range check","Keep all Microsoft.ML.* packages on the same version","Validate serialized pipeline options at startup"],"tags":["csharp","images","enum","resizing"],"backgroundTag":"invalid-enum-value","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}