{"record":{"id":"5d954cb89020259b","repo":"dotnet/wpf","slug":"sr-format-sr-rect-empty-rect","errorCode":null,"errorMessage":"SR.Format(SR.Rect_Empty, \"rect\")","messagePattern":"SR\\.Format\\(SR\\.Rect_Empty, \"rect\"\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/EllipseGeometry.cs","lineNumber":30,"sourceCode":"    public sealed partial class EllipseGeometry : Geometry \n    {\n        #region Constructors\n\n        /// <summary>\n        ///\n        /// </summary>\n        public EllipseGeometry()\n        {\n        }\n\n        /// <summary>\n        /// Constructor - sets the ellipse to the paramters with the given transformation\n        /// </summary>\n        public EllipseGeometry(Rect rect)\n        {\n            if (rect.IsEmpty) \n            {\n                throw new System.ArgumentException(SR.Format(SR.Rect_Empty, \"rect\"));\n            }\n\n            RadiusX = (rect.Right - rect.X) * (1.0 / 2.0);\n            RadiusY = (rect.Bottom - rect.Y) * (1.0 / 2.0);\n            Center = new Point(rect.X + RadiusX, rect.Y + RadiusY);\n        }\n        \n        /// <summary>\n        /// Constructor - sets the ellipse to the parameters\n        /// </summary>\n        public EllipseGeometry(\n            Point center, \n            double radiusX, \n            double radiusY)\n        {\n            Center = center;\n            RadiusX = radiusX;\n            RadiusY = radiusY;","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/EllipseGeometry.cs#L12-L48","documentation":"The EllipseGeometry(Rect) constructor requires a non-empty rectangle because it derives radius and center from rect dimensions. Passing Rect.Empty yields meaningless geometry, so the constructor throws ArgumentException with Rect_Empty.","triggerScenarios":"Calling new EllipseGeometry(rect) where rect.IsEmpty is true — typically a Rect field/property that was never initialized (default(Rect) or Rect.Empty) rather than computed from real bounds.","commonSituations":"Hit-testing or geometry code that passes a layout slot before it has been measured, data-bound Rect properties defaulting to Rect.Empty, or interop code returning an empty bounding box.","solutions":["Check rect.IsEmpty before constructing and skip or substitute a default geometry.","Ensure the Rect is computed from actual bounds (e.g. after Measure/Arrange) instead of relying on default(Rect).","Use a different constructor (center/radii) when the rectangle may be degenerate."],"exampleFix":"// before\nvar geo = new EllipseGeometry(rect);\n// after\nEllipseGeometry geo = rect.IsEmpty ? null : new EllipseGeometry(rect);","handlingStrategy":"validation","validationCode":"if (rect.IsEmpty) throw new ArgumentException(\"rect must not be empty\", nameof(rect));\nvar geo = new EllipseGeometry(rect);","typeGuard":"static bool IsValidRect(Rect r) => !r.IsEmpty && r.Width > 0 && r.Height > 0;","tryCatchPattern":"try { var geo = new EllipseGeometry(rect); }\ncatch (ArgumentException) { /* fall back to default geometry */ }","preventionTips":["Initialize Rect fields to finite bounds, not default(Rect)","Validate Rect-producing layout code before geometry construction"],"tags":["wpf","geometry","argument-validation"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}