我尝试在某些Windows 8.1计算机上启用拼写检查时遇到异常(两者都有最新更新,操作系统语言是俄语,.NET框架4.7是俄语)说:
System.Reflection.TargetInvocationException:调用目标抛出了异常。 ---> System.Runtime.InteropServices.COMException:无效的值 注册表(来自HRESULT的异常:0x80040153(REGDB_E_INVALIDVALUE)) 在System.StubHelpers.StubHelpers.GetWinRTFactoryObject(IntPtr pCPCMD) 在Windows.Data.Text.WordsSegmenter..ctor(String language)---结尾 内部异常堆栈跟踪--- at System.RuntimeMethodHandle.InvokeMethod(Object target,Object [] 参数,签名sig,布尔构造函数)at System.Reflection.RuntimeConstructorInfo.Invoke(的BindingFlags invokeAttr,Binder binder,Object []参数,CultureInfo文化) 在 MS.Internal.WindowsRuntime.ReflectionHelper.ReflectionNew [TArg1](类型 类型,TArg1 arg1)at MS.Internal.WindowsRuntime.Windows.Data.Text.WordsSegmenter..ctor(字符串 语言) MS.Internal.WindowsRuntime.Windows.Data.Text.WordsSegmenter.Create(字符串 language,Boolean shouldPreferNeutralSegmenter)at System.Windows.Documents.WinRTSpellerInterop.EnsureWordBreakerAndSpellCheckerForCulture(的CultureInfo culture,Boolean throwOnError)at System.Windows.Documents.WinRTSpellerInterop..ctor()at System.Windows.Documents.SpellerInteropBase.CreateInstance()at System.Windows.Documents.Speller.EnsureInitialized()at System.Windows.Documents.Speller.SetCustomDictionaries(CustomDictionarySources dictionaryLocations,Boolean add)at System.Windows.Documents.TextEditor.SetCustomDictionaries(布尔加法) 在 System.Windows.Controls.SpellCheck.OnIsEnabledChanged(DependencyObject的 d,DependencyPropertyChangedEventArgs e)at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs 吃 System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs 吃 System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex,DependencyProperty dp,PropertyMetadata元数据, EffectiveValueEntry oldEntry,EffectiveValueEntry& newEntry,布尔值 coerceWithDeferredReference,Boolean coerceWithCurrentValue, OperationType operationType)at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, 对象值,PropertyMetadata元数据,布尔值 coerceWithDeferredReference,Boolean coerceWithCurrentValue, OperationType operationType,Boolean isInternal)at System.Windows.DependencyObject.SetValue(DependencyProperty dp,Object 值)
此代码可用于重现此问题:
var richTextBox = new RichTextBox();
InputLanguageManager.SetInputLanguage(richTextBox,CultureInfo.GetCultureInfo("en-US"));
richTextBox.SetValue(SpellCheck.IsEnabledProperty, true);
在调查此问题时,我发现异常从s_WinRTType.ReflectionNew<string>(language);
抛出,其中 s_WinRTType描述类型“Windows.Data.Text.WordsSegmenter,Windows,ContentType = WindowsRuntime 。WordsSegmenter似乎是WinRT组件所以我无法看到它内部发生了什么。我想知道它为什么抛出REGDB_E_INVALIDVALUE /它寻找的值以及它应该是什么样子?
谢谢!
答案 0 :(得分:0)
您需要通过控制面板或使用DISM安装与语言包不同的语言功能。对我来说这需要.Net 4.7并且正在为windows 10 build 1709(秋季创建者更新)工作。我不知道这是否可以在Windows 8上使用。
如果您有权访问Windows更新(不在WSUS后面),您可以尝试安装它
Dism / Online / Add-Capability /CapabilityName:Language.Basic ~~~en-US~0.0.1.0
要检查已安装的功能,请显示所有已安装的选项:
dism / online / get-capabilities / limitaccess
背景资料:
https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/add-language-packs-to-windows
这最后一个链接解释了还有另一个版本2的功能需求。 对我来说,它解决了一个问题。
使用按需功能的isos(从msdn订阅下载它们):
对于Windows 10的(不知道这是否在Windows 8上可用): en_windows_10_features_on_demand_part_1_version_1709_updated_sept_2017_x64_dvd_100090755 en_windows_10_features_on_demand_part_2_version_1709_updated_sept_2017_x64_dvd_100090754
提取并安装:
dism / online / add-package /packagepath:d:\features\Microsoft-Windows-LanguageFeatures-Basic-en-us-Package.cab
PS:谷歌是否为REGDB_E_INVALIDVALUE:VSHost crash, REGDB_E_INVALIDVALUE loading Specific Project
实施例
您可以使用以下代码创建wpf测试应用程序: 这将读取可以使用的AvailableInputLanguages。 (对我来说,它并没有显示.Net 4中的4种语言,只有我用Dism安装的语言。
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ComboBox
ItemsSource="{Binding AvailableLanguages}"
SelectionChanged="OnLanguageSelectionChanged"
DisplayMemberPath="NativeName"/>
<TextBox x:Name="textBox" Grid.Row="1"
AcceptsReturn="True"
AcceptsTab="True"
SpellCheck.IsEnabled="True"
Text="Hello world"/>
</Grid>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
AvailableLanguages = new ObservableCollection<CultureInfo>();
foreach (CultureInfo culterInfo in InputLanguageManager.Current.AvailableInputLanguages)
{
AvailableLanguages.Add(culterInfo);
}
DataContext = this;
}
public ObservableCollection<CultureInfo> AvailableLanguages
{
get { return (ObservableCollection<CultureInfo>)GetValue(AvailableLanguagesProperty); }
set { SetValue(AvailableLanguagesProperty, value); }
}
public static readonly DependencyProperty AvailableLanguagesProperty = DependencyProperty.Register("AvailableLanguages", typeof(ObservableCollection<CultureInfo>), typeof(MainWindow));
private void OnLanguageSelectionChanged(object sender, SelectionChangedEventArgs e)
{
CultureInfo xmlLanguage = e.AddedItems[0] as CultureInfo;
textBox.Language = XmlLanguage.GetLanguage(xmlLanguage.Name);
}
}
答案 1 :(得分:0)
尝试:启动cmd(以管理员身份运行)
Dism /online /Add-Capability /capabilityname:Language.Basic~~~en-US~0.0.1.0