{"record":{"id":"00db15868bc0830a","repo":"dotnet/wpf","slug":"sr-size3d-dimensioncannotbenegative","errorCode":null,"errorMessage":"SR.Size3D_DimensionCannotBeNegative","messagePattern":"SR\\.Size3D_DimensionCannotBeNegative","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Rect3D.cs","lineNumber":58,"sourceCode":"            }\n            Debug.Assert(size.IsEmpty == IsEmpty);\n        }\n\n        /// <summary>\n        /// Constructor which sets the initial values to the values of the parameters.\n        /// SizeX, sizeY, sizeZ must be non-negative.\n        /// </summary>\n        /// <param name=\"x\">Value of the X location coordinate of the new rectangle.</param>\n        /// <param name=\"y\">Value of the X location coordinate of the new rectangle.</param>\n        /// <param name=\"z\">Value of the X location coordinate of the new rectangle.</param>\n        /// <param name=\"sizeX\">Size of the new rectangle in X dimension.</param>\n        /// <param name=\"sizeY\">Size of the new rectangle in Y dimension.</param>\n        /// <param name=\"sizeZ\">Size of the new rectangle in Z dimension.</param>\n        public Rect3D(double x, double y, double z, double sizeX, double sizeY, double sizeZ)\n        {\n            if (sizeX < 0 || sizeY < 0 || sizeZ < 0)\n            {\n                throw new System.ArgumentException(SR.Size3D_DimensionCannotBeNegative);\n            }\n\n            _x = x;\n            _y = y;\n            _z = z;\n            _sizeX = sizeX;\n            _sizeY = sizeY;\n            _sizeZ = sizeZ;\n        }\n\n        /// <summary>\n        /// Constructor which sets the initial values to bound the two points provided.\n        /// </summary>\n        /// <param name=\"point1\">First point.</param>\n        /// <param name=\"point2\">Second point.</param>\n        internal Rect3D(Point3D point1, Point3D point2)\n        {\n            _x = Math.Min(point1._x, point2._x);","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Rect3D.cs#L40-L76","documentation":"The Rect3D(x, y, z, sizeX, sizeY, sizeZ) constructor validates that no size dimension is negative; a Rect3D's extent along any axis cannot be less than zero. If any of sizeX, sizeY, or sizeZ is negative it throws ArgumentException with Size3D_DimensionCannotBeNegative.","triggerScenarios":"new Rect3D(x, y, z, sizeX, sizeY, sizeZ) where any size argument is < 0, e.g. new Rect3D(0,0,0, -5, 10, 10).","commonSituations":"Computing a size by subtracting points in the wrong order (max - min inverted); passing uninitialized/negative computed widths from layout math; data-driven dimensions from files or user input that can be negative.","solutions":["Clamp each size with Math.Max(0, size) before constructing the Rect3D.","Fix the underlying computation so sizes are max - min of the correct endpoints.","Order the two corner points first (take Min/Max per axis) and derive sizes from the ordered corners.","Validate input data and reject or sanitize negative dimensions upstream."],"exampleFix":"// before\nvar r = new Rect3D(p.X, p.Y, p.Z, a.X - b.X, a.Y - b.Y, a.Z - b.Z); // may be negative\n// after\nvar r = new Rect3D(p.X, p.Y, p.Z, Math.Abs(a.X - b.X), Math.Abs(a.Y - b.Y), Math.Abs(a.Z - b.Z));","handlingStrategy":"validation","validationCode":"if (sizeX < 0 || sizeY < 0 || sizeZ < 0) throw new ArgumentException(\"Rect3D dimensions cannot be negative\");\nvar r = new Rect3D(x, y, z, sizeX, sizeY, sizeZ);","typeGuard":"static bool IsValidSize(double sx, double sy, double sz) => sx >= 0 && sy >= 0 && sz >= 0;","tryCatchPattern":"try { var r = new Rect3D(x, y, z, sx, sy, sz); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"negative\"))\n{\n    var r = new Rect3D(x, y, z, Math.Max(0, sx), Math.Max(0, sy), Math.Max(0, sz));\n}","preventionTips":["Compute sizes as Math.Abs or max-min of ordered points","Clamp dimensions with Math.Max(0, value)","Validate dimension data at input boundaries","Watch for inverted min/max when subtracting points"],"tags":["wpf","media3d","rect3d","negative-value"],"backgroundTag":"argument-out-of-range","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"}