Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在Windows 10上使用国际键盘时WPF应用程序崩溃_C#_Wpf_Windows 10_Culture - Fatal编程技术网

C# 在Windows 10上使用国际键盘时WPF应用程序崩溃

C# 在Windows 10上使用国际键盘时WPF应用程序崩溃,c#,wpf,windows-10,culture,C#,Wpf,Windows 10,Culture,在具有英语国际键盘设置的Windows 10上测试WPF.Net应用程序会导致应用程序崩溃,错误为区域性ID 8192(0x2000)不是受支持的区域性。 在文本框中键入时会发生崩溃 该错误无法在Windows 7上重现,在Windows 10上设置其他键盘时已解决 目标框架是.NET3.5 stacktrace(法语)对我帮助不大,它直接进入了Microsoft的代码: System.ArgumentException: L'ID de culture 8192 (0x2000) n'est

在具有英语国际键盘设置的Windows 10上测试WPF.Net应用程序会导致应用程序崩溃,错误为
区域性ID 8192(0x2000)不是受支持的区域性。

在文本框中键入时会发生崩溃

该错误无法在Windows 7上重现,在Windows 10上设置其他键盘时已解决

目标框架是.NET3.5

stacktrace(法语)对我帮助不大,它直接进入了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()
正在寻求帮助,请


编辑:瞄准.NET4.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();
}

我在一个程序调用的库中遇到了这个问题,再多的修改Windows文化似乎也解决不了这个问题

最后,在深入挖掘堆栈跟踪并查看到底出了什么问题后,我想出了一个解决方案,对所有已安装的输入语言进行循环,跳过那些具有“损坏”区域性的语言,并将
System.Windows.Forms.InputLanguage.CurrentInputLanguage
设置为剩下的最适用的语言

可以专门检查键盘布局,因此使用第一个具有相同布局名称的布局应该可以完成这项工作,而不会造成任何混乱

代码需要对
System.Windows.Forms
的引用

InputLanguage origIpl = InputLanguage.CurrentInputLanguage;
Boolean fixIpl = false;
try
{
    // This causes the exception.
    CultureInfo ci = origIpl.Culture;
}
catch (ArgumentException)
{
    // detected the problem.
    fixIpl = true;
}
if (fixIpl)
{
    InputLanguage validIpl = null;
    InputLanguage preferredIpl = null;
    foreach (InputLanguage ipl in InputLanguage.InstalledInputLanguages)
    {
        try
        {
            // This causes the exception.
            CultureInfo ci = ipl.Culture;
            // Store the first one that survives the above call
            if (validIpl == null)
                validIpl = ipl;
            // See if there is one with identical layout. If not, keep looking.
            if (origIpl.LayoutName != ipl.LayoutName)
                continue;
            // Found 1:1 match: store and abort loop.
            preferredIpl = ipl;
            break;
        }
        catch (ArgumentException)
        {
            /* skip languages that raise the exception here. */
        }
    }
    if (validIpl != null)
        InputLanguage.CurrentInputLanguage = preferredIpl ?? validIpl;
    // else case here could give some kind of warning?
    // Not sure if it's possible to NOT have any standard input languages.
}

你有没有试过用英语和谷歌搜索错误?是的,但对我没有多大帮助…你能把它贴在这里给说英语的用户吗?(不是翻译,确切的消息)根据我的搜索,这应该是我帖子的第二行。最后谷歌搜索让我找到了这一行:“这看起来像是.NETFramework3.5的win10中的一个bug。”“是的,这是另一种解决办法。但就个人而言,对于此类问题,我更倾向于警告用户这个问题,让用户自己找到解决方案。这避免了过多的考虑因素,让用户能够掌握正在发生的事情……好吧,如果像我的情况一样,是一个特定的调用导致了崩溃,那么您总是可以在操作完成后立即重置它,因此它对用户正在做的任何事情都没有实际影响。我使用了一个
try finally
块,其中
finally
部分检查了上面代码中提到的
fixIpl
布尔值。