{"record":{"id":"400921f8ba33c43f","repo":"dotnet/wpf","slug":"sr-format-sr-inputmethod-invalidsentencemode-value","errorCode":null,"errorMessage":"SR.Format(SR.InputMethod_InvalidSentenceMode, value)","messagePattern":"SR\\.Format\\(SR\\.InputMethod_InvalidSentenceMode, value\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputMethod.cs","lineNumber":1062,"sourceCode":"                            ret |= ImeSentenceModeValues.SingleConversion;\n                        if ((sentence & NativeMethods.IME_SMODE_AUTOMATIC) != 0)\n                            ret |= ImeSentenceModeValues.Automatic;\n                        if ((sentence & NativeMethods.IME_SMODE_PHRASEPREDICT) != 0)\n                            ret |= ImeSentenceModeValues.PhrasePrediction;\n                        if ((sentence & NativeMethods.IME_SMODE_CONVERSATION) != 0)\n                            ret |= ImeSentenceModeValues.Conversation;\n    \n                        return ret;\n                    }\n                }\n                return ImeSentenceModeValues.None;\n            }\n\n            set\n            {\n                if (!IsValidSentenceMode(value))\n                {\n                    throw new ArgumentException(SR.Format(SR.InputMethod_InvalidSentenceMode, value));\n                }\n\n                Debug.Assert((value & ImeSentenceModeValues.DoNotCare) == 0);\n\n                //\n                // Update Cicero's sentence mode.\n                //\n                TextServicesCompartment compartment;\n                compartment = TextServicesCompartmentContext.Current.GetCompartment(InputMethodStateType.ImeSentenceModeValues);\n\n                if (compartment != null)\n                {\n                    UnsafeNativeMethods.SentenceModeFlags convmode = 0;\n\n                    if ((value & ImeSentenceModeValues.PluralClause) != 0)\n                        convmode |= UnsafeNativeMethods.SentenceModeFlags.TF_SENTENCEMODE_PLAURALCLAUSE;\n                    if ((value & ImeSentenceModeValues.SingleConversion) != 0)\n                        convmode |= UnsafeNativeMethods.SentenceModeFlags.TF_SENTENCEMODE_SINGLECONVERT;","sourceCodeStart":1044,"sourceCodeEnd":1080,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputMethod.cs#L1044-L1080","documentation":"InputMethod.SentenceMode setter throws ArgumentException with SR.InputMethod_InvalidSentenceMode when the value is not a valid ImeSentenceModeValues combination, as determined by IsValidSentenceMode. The sentence mode configures IME sentence-conversion behavior and is validated before being forwarded to Cicero.","triggerScenarios":"Assigning an undefined or out-of-range ImeSentenceModeValues value to InputMethod.SentenceMode, typically a raw int cast or an OR of unrelated flags.","commonSituations":"Restoring saved IME settings from config or per-user storage with stale values; programmatic IME configuration for Japanese input where constants were hand-coded incorrectly.","solutions":["Assign only values from the ImeSentenceModeValues enum (None, Automatic, Prediction, Conversation).","Validate restored settings: if not ((v & ~ImeSentenceModeValues.None) == 0 || defined flags) reset to ImeSentenceModeValues.None.","Use try-catch for ArgumentException when applying user-provided settings and fall back to the default mode."],"exampleFix":"// before\nime.SentenceMode = (ImeSentenceModeValues)userSetting;\n// after\nvar v = (ImeSentenceModeValues)userSetting;\nime.SentenceMode = Enum.IsDefined(typeof(ImeSentenceModeValues), v)\n    ? v : ImeSentenceModeValues.Automatic;","handlingStrategy":"validation","validationCode":"static readonly ImeSentenceModeValues ValidSentenceMask =\n    ImeSentenceModeValues.None | ImeSentenceModeValues.Automatic |\n    ImeSentenceModeValues.Prediction | ImeSentenceModeValues.Conversation;\nif (((int)value & ~(int)ValidSentenceMask) != 0) value = ImeSentenceModeValues.Automatic;","typeGuard":"static bool IsValidSentenceModeValue(ImeSentenceModeValues v) =>\n    Enum.IsDefined(typeof(ImeSentenceModeValues), v);","tryCatchPattern":"try { ime.SentenceMode = v; }\ncatch (ArgumentException) { ime.SentenceMode = ImeSentenceModeValues.Automatic; }","preventionTips":["Use only named ImeSentenceModeValues members; avoid raw int casts.","Validate settings loaded from config/user stores before applying.","Round-trip test persisted IME settings across framework versions."],"tags":["wpf","input-method","ime","invalid-argument"],"backgroundTag":"invalid-enum-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"}