{"record":{"id":"c7bbd7c6e8b0e4bb","repo":"stride3d/stride","slug":"argumentoutofrangeexception-orientation","errorCode":null,"errorMessage":"ArgumentOutOfRangeException: orientation","messagePattern":"ArgumentOutOfRangeException: orientation","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Physics/Shapes/CapsuleColliderShape.cs","lineNumber":68,"sourceCode":"\n                case ShapeOrientation.UpY:\n                    shape = new CapsuleShape(radius, length)\n                    {\n                        LocalScaling = cachedScaling,\n                    };\n                    rotation = Matrix.Identity;\n                    break;\n\n                case ShapeOrientation.UpX:\n                    shape = new CapsuleShapeX(radius, length)\n                    {\n                        LocalScaling = cachedScaling,\n                    };\n                    rotation = Matrix.RotationZ(MathF.PI / 2.0f);\n                    break;\n\n                default:\n                    throw new ArgumentOutOfRangeException(\"orientation\");\n            }\n\n            InternalShape = Is2D ? (CollisionShape)new Convex2DShape(shape) { LocalScaling = cachedScaling } : shape;\n\n            DebugPrimitiveMatrix = Matrix.Scaling(new Vector3(DebugScaling)) * rotation;\n        }\n\n        public override MeshDraw CreateDebugPrimitive(GraphicsDevice device)\n        {\n            return GeometricPrimitive.Capsule.New(device, Length, Radius).ToMeshDraw();\n        }\n\n        public override Vector3 Scaling\n        {\n            get { return base.Scaling; }\n            set\n            {\n                Vector3 newScaling;","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/Shapes/CapsuleColliderShape.cs#L50-L86","documentation":"The CapsuleColliderShape constructor switches on the requested ShapeOrientation (UpX/UpY/UpZ) to build the capsule and pick a debug rotation. An unrecognized orientation value reaches the default case and throws ArgumentOutOfRangeException(\"orientation\").","triggerScenarios":"Constructing new CapsuleColliderShape(...) with an invalid or uninitialized ShapeOrientation enum value (cast from an out-of-range int, or a config field holding a bad value).","commonSituations":"Orientation read from an asset/property serialized as an int that doesn't map to a defined enum member; upgrading Stride where enum members changed.","solutions":["Pass only valid ShapeOrientation values: UpX, UpY, or UpZ.","Validate any int-to-enum cast with Enum.IsDefined before constructing the shape.","Fix the serialized asset/config field that holds the out-of-range orientation value."],"exampleFix":"// before\nvar shape = new CapsuleColliderShape(radius, length, (ShapeOrientation)7);\n// after\nif (!Enum.IsDefined(typeof(ShapeOrientation), orientationValue))\n    throw new ArgumentException($\"Invalid orientation: {orientationValue}\");\nvar shape = new CapsuleColliderShape(radius, length, ShapeOrientation.UpY);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(ShapeOrientation), orientation))\n    throw new ArgumentException($\"Invalid ShapeOrientation: {orientation}\");","typeGuard":"bool IsValidOrientation(ShapeOrientation o) => o is ShapeOrientation.UpX or ShapeOrientation.UpY or ShapeOrientation.UpZ;","tryCatchPattern":"try { var s = new CapsuleColliderShape(r, len, o); }\ncatch (ArgumentOutOfRangeException) { /* use default orientation */ }","preventionTips":["Never cast raw ints to ShapeOrientation without Enum.IsDefined.","Prefer passing enum literals at call sites.","Keep serialized orientation fields validated on load."],"tags":["physics","enum","constructor"],"backgroundTag":"invalid-enum-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}