I have a WPF application targeting .NET 4.5.2 (but typically running under 4.6.1) and I've enabled spell checking on a couple of TextBoxes and DataGridTextColumns. Spell check is enabled via a style depending on what language the user has selected (we currently only support en). The application and system cultures are all set to en or en-US. I am not using any custom dictionaries.
Spellcheck is enabled via the following style:
<Style TargetType="TextBox">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Source={x:Static Properties:Settings.Default}, Path=Culture}"
Value="en" />
<Condition Binding="{Binding Source={x:Static diagnostics:Debugger.IsAttached}}"
Value="False" />
</MultiDataTrigger.Conditions>
<Setter Property="SpellCheck.IsEnabled"
Value="True" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
(We store the last selected application culture using the built-in ApplicationSettings object, and only save the most generic parent culture. If the user's system is set to "en-US", we'll just store "en" to simplify things.)
The TextBox is defined in a DataTemplate that is used for TreeViewItems, in case that makes any difference. Users are more likely to edit the TextBox rather than the DataGrid, so I suspect the issue is related to the TextBox.
On Windows 8 and 10, some users are experience a crash in the spell checker with the following stack trace:
System.ObjectDisposedException: Safe handle has been closed
at System.Threading.WaitHandle.WaitOneNative(SafeHandle waitableSafeHandle, UInt32 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
at System.Threading.WaitHandle.InternalWaitOne(SafeHandle waitableSafeHandle, Int64 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
at System.Threading.WaitHandle.WaitOne(Int32 millisecondsTimeout, Boolean exitContext)
at System.Windows.Documents.WinRTSpellerInterop.ClearDictionaries(Boolean isDisposeOrFinalize)
at System.Windows.Documents.WinRTSpellerInterop.Dispose(Boolean disposing)
at System.Windows.Documents.WinRTSpellerInterop.Finalize()
I've searched Google, StackOverflow, and MSDN but can't find any reference to this issue. I don't know what my users are doing to trigger this case and I have been unable to reproduce it myself. My logs indicate they are not editing the spellcheck-enabled fields when this happens (in fact, the last editing they did was at least a minute or 2 prior to the exception). Does anyone have any ideas?
This issue is resolved in .NET 4.7 (see the "WPF Spellchecker" entry on the Runtime Changes page). Note that NET 4.7 will not install on Windows 10 November Update or earlier. However, most Windows 10 users should already be on the Anniversary Update by now.
Starting with the .NET Framework 4.6.1, the spellchecker in WPF applications occasionally throws an ObjectDisposedException during application shutdown.
In the .NET Framework 4.7, the exception is handled gracefully by the runtime, thus ensuring that applications are no longer adversely affected. It should be noted that occasional first-chance exceptions continue to be observed in applications running under a debugger.