{"record":{"id":"7d2211e3add63997","repo":"dotnet/wpf","slug":"sr-image-sizeoptionsangle","errorCode":null,"errorMessage":"SR.Image_SizeOptionsAngle","messagePattern":"SR\\.Image_SizeOptionsAngle","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapSizeOptions.cs","lineNumber":176,"sourceCode":"            return sizeOptions;\n        }\n\n        /// <summary>\n        /// Constructs an BitmapSizeOptions that does not preserve the aspect ratio and\n        /// instead uses dimensions pixelWidth x pixelHeight.\n        /// </summary>\n        /// <param name=\"rotation\">Angle to rotate</param>\n        public static BitmapSizeOptions FromRotation(Rotation rotation)\n        {\n            switch(rotation)\n            {\n                case Rotation.Rotate0:\n                case Rotation.Rotate90:\n                case Rotation.Rotate180:\n                case Rotation.Rotate270:\n                    break;\n                default:\n                    throw new ArgumentException(SR.Image_SizeOptionsAngle, nameof(rotation));\n            }\n\n            BitmapSizeOptions sizeOptions = new BitmapSizeOptions\n            {\n                _rotationAngle = rotation,\n                _preservesAspectRatio = true,\n                _pixelWidth = 0,\n                _pixelHeight = 0\n            };\n\n            return sizeOptions;\n        }\n\n        // Note: In this method, newWidth, newHeight are not affected by the\n        // rotation angle.\n        internal void GetScaledWidthAndHeight(\n            uint width,\n            uint height,","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapSizeOptions.cs#L158-L194","documentation":"BitmapSizeOptions.FromRotation validates its Rotation parameter and throws ArgumentException with SR.Image_SizeOptionsAngle when the value is not one of Rotation.Rotate0/90/180/270. Rotation is a bounded enum and any other value (e.g. a casted invalid int) is rejected.","triggerScenarios":"Calling BitmapSizeOptions.FromRotation((Rotation)45) or passing a default/uninitialized Rotation value cast from an out-of-range integer.","commonSituations":"Computing rotation angles dynamically (arbitrary degrees) and casting to Rotation; deserializing a rotation setting from config that holds a non-multiple-of-90 value.","solutions":["Restrict rotation values to multiples of 90 degrees using the Rotation enum members.","Validate the numeric source with a bounds check before casting to Rotation.","If arbitrary-angle rotation is needed, use TransformedBitmap with a RotateTransform instead of FromRotation."],"exampleFix":"// before\nvar opts = BitmapSizeOptions.FromRotation((Rotation)angle); // angle=45\n// after\nvar opts = BitmapSizeOptions.FromRotation((Rotation)((angle / 90) * 90 % 360));","handlingStrategy":"validation","validationCode":"if (angle % 90 != 0 || angle < 0 || angle > 270)\n    throw new ArgumentOutOfRangeException(nameof(angle));\nvar rotation = (Rotation)angle;","typeGuard":"bool IsValidRotation(Rotation r) => r is Rotation.Rotate0 or Rotation.Rotate90 or Rotation.Rotate180 or Rotation.Rotate270;","tryCatchPattern":"try { var opts = BitmapSizeOptions.FromRotation(rotation); } catch (ArgumentException ex) { /* fix rotation param */ }","preventionTips":["Only use Rotation enum members, never raw casts","Validate config-driven angles are multiples of 90","Use RotateTransform/TransformedBitmap for arbitrary angles"],"tags":["wpf","imaging","enum","argument"],"backgroundTag":"invalid-enum-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}