{"record":{"id":"6c616c2670b13e3f","repo":"stride3d/stride","slug":"nameof-locktype-is-invalid-type","errorCode":null,"errorMessage":"{ nameof(lockType) } is invalid type","messagePattern":"(.+?) is invalid type","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Physics/Shapes/HeightfieldColliderShape.cs","lineNumber":194,"sourceCode":"        internal HeightArrayLock(LockTypes lockType, ReaderWriterLockSlim lockSlim)\n        {\n            if (lockSlim == null)\n            {\n                throw new ArgumentNullException(nameof(lockSlim));\n            }\n\n            readerWriterLockSlim = lockSlim;\n\n            switch (lockType)\n            {\n                case LockTypes.Read:\n                    readerWriterLockSlim.EnterReadLock();\n                    break;\n                case LockTypes.ReadWrite:\n                    readerWriterLockSlim.EnterWriteLock();\n                    break;\n                default:\n                    throw new ArgumentException($\"{ nameof(lockType) } is invalid type\");\n            }\n        }\n\n        public void Unlock()\n        {\n            if (readerWriterLockSlim.IsReadLockHeld)\n            {\n                readerWriterLockSlim.ExitReadLock();\n            }\n            else if (readerWriterLockSlim.IsWriteLockHeld)\n            {\n                readerWriterLockSlim.ExitWriteLock();\n            }\n        }\n\n        public void Dispose()\n        {\n            Unlock();","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/Shapes/HeightfieldColliderShape.cs#L176-L212","documentation":"HeightArrayLock's constructor only handles LockTypes.Read and LockTypes.ReadWrite; any other lockType (e.g. a cast int or removed enum member) reaches the default case and throws ArgumentException \"{ lockType } is invalid type\".","triggerScenarios":"new HeightArrayLock((LockTypes)123, lockSlim) or calling the shape's Lock API with an invalid LockTypes value.","commonSituations":"LockTypes value built from numeric config; enum drift between library versions.","solutions":["Pass only LockTypes.Read or LockTypes.ReadWrite.","Validate with Enum.IsDefined(typeof(LockTypes), value) before constructing.","Fix numeric serialization of the lock type in calling code."],"exampleFix":"// before\nusing var l = new HeightArrayLock((LockTypes)mode, lockSlim);\n// after\nvar lt = mode == 0 ? LockTypes.Read : LockTypes.ReadWrite;\nusing var l = new HeightArrayLock(lt, lockSlim);","handlingStrategy":"validation","validationCode":"if (lockType is not (LockTypes.Read or LockTypes.ReadWrite))\n    throw new ArgumentException($\"Invalid lockType: {lockType}\");","typeGuard":"bool IsValidLockType(LockTypes t) => t is LockTypes.Read or LockTypes.ReadWrite;","tryCatchPattern":"try { using var l = new HeightArrayLock(lockType, lockSlim); }\ncatch (ArgumentException) { /* default to LockTypes.Read */ }","preventionTips":["Only use the two defined LockTypes members.","Avoid numeric casts of LockTypes.","Wrap lock acquisition in using scopes so Unlock always runs."],"tags":["physics","enum","locking"],"backgroundTag":"invalid-enum-argument","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"}