Тестирование приложения WPF .Net в Windows 10 с английской международной настройкой клавиатуры вызывает сбой приложения с ошибкой Culture ID 8192 (0x2000) is not a supported culture.
Сбой происходит при наборе текста в текстовых полях.
Ошибка не может быть воспроизведена в Windows 7 и устраняется в Windows 10 при установке другой клавиатуры.
Целевой фреймворк .Net 3.5.
Трассировка стека (на французском) мне не сильно помогает, она идет прямо в код Microsoft:
System.ArgumentException: L'ID de culture 8192 (0x2000) n'est pas une culture prise en charge.
Nom du paramètre : culture
à System.Globalization.CultureTableRecord.GetCultureTableRecord(Int32 cultureId, Boolean useUserOverride)
à System.Globalization.CultureInfo..ctor(Int32 culture, Boolean useUserOverride)
à System.Windows.Input.InputLanguageSource.get_CurrentInputLanguage()
à System.Windows.Input.InputLanguageManager.get_CurrentInputLanguage()
à System.Windows.Documents.TextSelection.EnsureCaret(Boolean isBlinkEnabled, CaretScrollMethod scrollMethod)
à System.Windows.Documents.TextSelection.System.Windows.Documents.ITextSelection.UpdateCaretAndHighlight()
à System.Windows.Documents.TextEditor.OnGotKeyboardFocus(Object sender, KeyboardFocusChangedEventArgs e)
à System.Windows.Controls.Primitives.TextBoxBase.OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
à System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
à System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
à System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
à System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
à System.Windows.Input.InputManager.ProcessStagingArea()
à System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
à System.Windows.Input.KeyboardDevice.ChangeFocus(DependencyObject focus, Int32 timestamp)
à System.Windows.Input.KeyboardDevice.Focus(DependencyObject focus, Boolean askOld, Boolean askNew)
à System.Windows.Input.KeyboardDevice.Focus(IInputElement element)
à System.Windows.UIElement.Focus()
à System.Windows.Documents.TextEditorMouse.MoveFocusToUiScope(TextEditor This)
à System.Windows.Documents.TextEditorMouse.OnMouseDown(Object sender, MouseButtonEventArgs e)
à System.Windows.Controls.Primitives.TextBoxBase.OnMouseDown(MouseButtonEventArgs e)
à System.Windows.UIElement.OnMouseDownThunk(Object sender, MouseButtonEventArgs e)
à System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
à System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
à System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
à System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
à System.Windows.Input.InputManager.ProcessStagingArea()
à System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
à System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
à System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
à System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
à System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
à MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
à MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
à System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
à System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
à System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
à MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
à MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
à System.Windows.Threading.Dispatcher.TranslateAndDispatchMessage(MSG& msg)
à System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
à System.Windows.Application.RunInternal(Window window)
à MyApp.App.Main()
Нужна помощь, пожалуйста ...
РЕДАКТИРОВАТЬ: таргетинг .Net 4.0 решает проблему.Но печальная вещь заключается в том, что мы должны нацеливаться на 3.5, чтобы обеспечить совместимость со старой ОС для этого приложения.
Этот факт делает вопрос довольно странным, но я бы хотел оставить его открытым, если кто-то может принести некоторую помощь.
РЕШЕНИЕ: Это скорее решение проблемы, чем решение:мы добавили к OnStartup(StartupEventArgs e)
некоторый код, чтобы предупредить пользователя, если настройки культуры вызывают исключение и закрывают приложение:
try
{
CultureInfo cul = new CultureInfo(System.Windows.Forms.InputLanguage.CurrentInputLanguage.Culture.LCID, true);
}
catch
{
//warn the user...
Current.Shutdown();
}