2

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?

19
  • 1
    The SpellCheck.IsEnabled property is a trigger, setting it to false causes the class object to be disposed. Exactly how that interacts so poorly with the finalizer is pretty hard to see, it is not supposed to run. You need to ask these users what version of .NET they have installed on their machine. And of course recommend they update when it is old. Commented Jun 8, 2016 at 15:50
  • 1
    @HansPassant My users are not attaching a debugger, I'm using the Microsoft.Diagnostics.Runtime library to log the stack trace of all my threads when an unhandled exception occurs. I'll post on the MSDN forums and see what I get. Commented Jun 8, 2016 at 16:32
  • 1
    @Vatsan Unfortunately I have no idea how to reproduce the problem myself. I've tried reproducing my customers' actions as best I can from the logs I've received, but so far no luck. Commented Jun 10, 2016 at 16:54
  • 1
    @Vatsan Finally posted the issue to Connect here. I was also able to get a dump file, but it's too large to post to the Connect issue (1 GB). Commented Jun 15, 2016 at 21:05
  • 2
    @Vatsan Microsoft responded yesterday that a fix is expected in the next version of .NET. Commented Oct 20, 2016 at 18:57

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.