{"record":{"id":"eef32e8e60558ba7","repo":"dotnet/wpf","slug":"sr-inputmethod-invalidconversionmode-value","errorCode":null,"errorMessage":"SR.InputMethod_InvalidConversionMode (value)","messagePattern":"SR\\.InputMethod_InvalidConversionMode \\(value\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputMethod.cs","lineNumber":811,"sourceCode":"                        if ((convmode & NativeMethods.IME_CMODE_EUDC) != 0)\n                            ret |= ImeConversionModeValues.Eudc;\n                        if ((convmode & NativeMethods.IME_CMODE_SYMBOL) != 0)\n                            ret |= ImeConversionModeValues.Symbol;\n                        if ((convmode & NativeMethods.IME_CMODE_FIXED) != 0)\n                            ret |= ImeConversionModeValues.Fixed;\n\n                        return ret;\n                    }\n                }\n\n                return ImeConversionModeValues.Alphanumeric;\n            }\n\n            set\n            {\n                if (!IsValidConversionMode(value))\n                {\n                    throw new ArgumentException(SR.Format(SR.InputMethod_InvalidConversionMode, value));\n                }\n\n                Debug.Assert((value & ImeConversionModeValues.DoNotCare) == 0);\n\n                IntPtr hwnd = IntPtr.Zero;\n                if (_immEnabled)\n                {\n                    hwnd = HwndFromInputElement(Keyboard.FocusedElement);\n                }\n\n\n                //\n                // Update Cicero's conversion mode.\n                //\n                TextServicesCompartment compartment;\n                compartment = TextServicesCompartmentContext.Current.GetCompartment(InputMethodStateType.ImeConversionModeValues);\n\n                if (compartment != null)","sourceCodeStart":793,"sourceCodeEnd":829,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputMethod.cs#L793-L829","documentation":"InputMethod.ConversionMode setter throws ArgumentException wrapping SR.InputMethod_InvalidConversionMode when the value fails IsValidConversionMode, i.e. it is not a valid combination of ImeConversionModeValues flags (Native, Katakana, FullShape, Roman, CharPrecision, etc.). Invalid flag combos or out-of-range bits are rejected before the mode is pushed to the IME/Cicero.","triggerScenarios":"Assigning a value to InputMethod.ConversionMode that is not one of the defined ImeConversionModeValues combinations, e.g. an undefined bit, negative value, or a combination including DoNotCare mixed with other flags.","commonSituations":"Persisting/restoring IME modes from config files or the registry where stale or hand-edited numeric values appear; computing modes with bitwise OR of unintended constants; localization code for Japanese/Chinese/Korean IMEs.","solutions":["Only assign values built from ImeConversionModeValues enum members (bitwise OR of valid flags).","Mask or validate the stored value before applying it: if ((v & ~ImeConversionModeValues.Alphanumeric) != 0) fall back to a default.","Wrap the setter in try-catch for ArgumentException and reset to ImeConversionModeValues.DoNotCare on failure when loading legacy settings."],"exampleFix":"// before\nime.ConversionMode = (ImeConversionModeValues)storedInt; // may be invalid\n// after\nvar v = (ImeConversionModeValues)storedInt;\nime.ConversionMode = (v & ImeConversionModeValues.DoNotCare) != 0 || (v & ~validMask) != 0\n    ? ImeConversionModeValues.DoNotCare : v;","handlingStrategy":"validation","validationCode":"static readonly ImeConversionModeValues ValidMask =\n    ImeConversionModeValues.Alphanumeric | ImeConversionModeValues.Native |\n    ImeConversionModeValues.Katakana | ImeConversionModeValues.FullShape |\n    ImeConversionModeValues.Roman | ImeConversionModeValues.CharPrecision |\n    ImeConversionModeValues.Symbol | ImeConversionModeValues.Fixed;\nif (((int)value & ~(int)ValidMask) != 0) value = ImeConversionModeValues.DoNotCare;","typeGuard":"static bool IsValidConversionModeValue(ImeConversionModeValues v) =>\n    (v & ~(ImeConversionModeValues)0x1FFFF) == 0;","tryCatchPattern":"try { ime.ConversionMode = v; }\ncatch (ArgumentException) { ime.ConversionMode = ImeConversionModeValues.DoNotCare; }","preventionTips":["Build mode values only via bitwise OR of named ImeConversionModeValues constants.","Mask stored/restored settings against a valid bitmask before applying.","Persist enum names, not raw ints, when saving IME settings."],"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"}