{"record":{"id":"c9f4232f3aa4cb5b","repo":"dotnet/wpf","slug":"sr-textstore-badlockflags","errorCode":null,"errorMessage":"SR.TextStore_BadLockFlags","messagePattern":"SR\\.TextStore_BadLockFlags","errorType":"error_code","errorClass":"COMException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs","lineNumber":124,"sourceCode":"                throw new COMException(SR.TextStore_CONNECT_E_NOCONNECTION, unchecked((int)0x80040200));\n            }\n\n            Marshal.ReleaseComObject(_sink);\n            _sink = null;\n\n            // We don't need to track window movement for this textstore any more.\n            // _sink was the only consumer.\n            _textservicesHost.UnregisterWinEventSink(this);\n        }\n\n        // See msdn's ITextStoreACP documentation for a full description.\n        public void RequestLock(UnsafeNativeMethods.LockFlags flags, out int hrSession)\n        {\n            if (!HasSink)\n                throw new COMException(SR.TextStore_NoSink);\n\n            if (flags == 0)\n                throw new COMException(SR.TextStore_BadLockFlags);\n\n            bool isReplayingIMEChanges =  (_replayingIMEChangeReentrancyCount > 0);\n\n            if (IsTracing)\n            {\n                IMECompositionTracer.Trace(this, IMECompositionTraceOp.BRequestLock,\n                                            \"f:\", flags,\n                                            \"lf:\", _lockFlags,\n                                            \"icr:\", _replayingIMEChangeReentrancyCount,\n                                            \"ric:\", isReplayingIMEChanges,\n                                            \"tcr:\", _textChangeReentrencyCount,\n                                            \"paf:\", _pendingAsyncLockFlags);\n                if (_replayingIMEChangeReentrancyCount != 0)\n                {\n                    IMECompositionTracer.Mark(new System.Diagnostics.StackTrace(true));\n                }\n            }\n","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs#L106-L142","documentation":"TextStore.RequestLock throws this COMException when a TSF (Text Services Framework) client requests a document lock with a flags value of 0 (no TS_LF_READ/TS_LF_WRITE bits set). A lock request must ask for at least read or write access; a zero-flag request is meaningless and rejected immediately. The HRESULT is E_INVALIDARG-style failure surfaced back to the IME/text service via hrSession.","triggerScenarios":"A text service calls ITextStoreACP::RequestLock with dwLockFlags == 0, i.e. neither TS_LF_READ nor TS_LF_WRITE nor TS_LF_READWRITE requested.","commonSituations":"Buggy or third-party IME/text services that zero-initialize the lock flags struct and forget to OR in the desired access bits; interop marshaling code passing an empty enum value.","solutions":["Fix the calling text service to pass a valid lock mask (TS_LF_READ, TS_LF_WRITE, or both) to RequestLock.","If you own interop wrappers, ensure the LockFlags enum value is preserved across the marshaling boundary and not defaulted to 0.","Reproduce with a specific IME installed; update or replace the offending IME/text service."],"exampleFix":"// before (caller side)\nLockFlags flags = 0;\nstore.RequestLock(flags, out hrSession);\n// after\nLockFlags flags = LockFlags.TS_LF_READ | LockFlags.TS_LF_WRITE;\nstore.RequestLock(flags, out hrSession);","handlingStrategy":"validation","validationCode":"if ((lockFlags & (LockFlags.TS_LF_READ | LockFlags.TS_LF_WRITE)) == 0) { /* fix flags before calling RequestLock */ }","typeGuard":null,"tryCatchPattern":"try { store.RequestLock(flags, out hrSession); } catch (COMException ex) { /* handle bad lock flags */ }","preventionTips":["Always OR in at least TS_LF_READ or TS_LF_WRITE when requesting a lock","Verify enum values survive interop marshaling","Test with all IMEs your users install"],"tags":["wpf","tsf","ime","invalid-argument"],"backgroundTag":"invalid-flag-value","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"}