{"record":{"id":"cb84689922deaf84","repo":"dotnet/wpf","slug":"sr-rect3d-cannotmodifyemptyrect","errorCode":null,"errorMessage":"SR.Rect3D_CannotModifyEmptyRect","messagePattern":"SR\\.Rect3D_CannotModifyEmptyRect","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Rect3D.cs","lineNumber":143,"sourceCode":"            {\n                return _sizeX < 0;\n            }\n        }\n\n        /// <summary>\n        /// The point representing the origin of the rectangle.\n        /// </summary>\n        public Point3D Location\n        {\n            get\n            {\n                return new Point3D(_x, _y, _z);\n            }\n            set\n            {\n                if (IsEmpty)\n                {\n                    throw new System.InvalidOperationException(SR.Rect3D_CannotModifyEmptyRect);\n                }\n\n                _x = value._x;\n                _y = value._y;\n                _z = value._z;\n            }\n        }\n\n        /// <summary>\n        /// The size representing the area of the rectangle.\n        /// </summary>\n        public Size3D Size\n        {\n            get\n            {\n                if( IsEmpty )\n                    return Size3D.Empty;\n                else","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/Rect3D.cs#L125-L161","documentation":"Rect3D.Location cannot be set while the rectangle is Empty (Rect3D.Empty, whose fields are all positive-infinity sentinels). Because an empty rect has no defined position, assigning a location first would leave it inconsistent, so the setter throws InvalidOperationException with Rect3D_CannotModifyEmptyRect.","triggerScenarios":"rect.Location = new Point3D(...) where rect == Rect3D.Empty (e.g. created via the default ctor or Rect3D.Empty).","commonSituations":"Starting from Rect3D.Empty and trying to grow it by assigning Location/Size directly; properties initialized to Rect3D.Empty then mutated; union/bounds results that came back empty being modified.","solutions":["Assign the whole rect instead: rect = new Rect3D(point, size) rather than setting Location on the empty rect.","Replace the empty value with a new non-empty Rect3D before mutating Location.","Check rect.IsEmpty before assigning and construct a fresh instance in that branch.","Track your own 'has bounds' flag and construct the Rect3D from scratch once the first point/size is known."],"exampleFix":"// before\nRect3D r = Rect3D.Empty;\nr.Location = new Point3D(1,2,3); // InvalidOperationException\n// after\nRect3D r = new Rect3D(new Point3D(1,2,3), new Size3D(0,0,0));","handlingStrategy":"validation","validationCode":"if (rect.IsEmpty) rect = new Rect3D(newPoint, new Size3D(0,0,0)); else rect.Location = newPoint;","typeGuard":"static bool CanMutate(this Rect3D r) => !r.IsEmpty;","tryCatchPattern":"try { rect.Location = p; }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"empty\"))\n{\n    rect = new Rect3D(p, new Size3D(0,0,0));\n}","preventionTips":["Never mutate Rect3D.Empty in place; construct a new instance","Seed bounds with a zero-size Rect3D instead of Rect3D.Empty","Check IsEmpty before any property assignment","Prefer Rect3D.Union over manual Location/Size edits when accumulating"],"tags":["wpf","media3d","rect3d","empty-rect"],"backgroundTag":"invalid-state-transition","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"}