Skip to content

Instantly share code, notes, and snippets.

@hmemcpy
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save hmemcpy/9447256 to your computer and use it in GitHub Desktop.

Select an option

Save hmemcpy/9447256 to your computer and use it in GitHub Desktop.
Why do u crash?????
<entry>
<record>10589</record>
<time>2014/03/09 11:56:50.360</time>
<type>Error</type>
<source>Editor or Editor Extension</source>
<description>System.InvalidOperationException: Attempting to get the view from an adapter in state Closed
at Microsoft.VisualStudio.Editor.Implementation.SimpleTextViewWindow.get_WpfTextViewHost()
at Microsoft.VisualStudio.Editor.Implementation.SimpleTextViewWindow.ClearCommandContext()
at Microsoft.VisualStudio.Editor.Implementation.VsMouseProcessor.PostprocessMouseLeftButtonUp(MouseButtonEventArgs e)
at Microsoft.VisualStudio.Text.Utilities.WpfMouseProcessor.&lt;&gt;c__DisplayClass30.&lt;UIElement_MouseLeftButtonUp&gt;b__29()
at Microsoft.VisualStudio.Text.Utilities.GuardedOperations.CallExtensionPoint(Object errorSource, Action call)</description>
</entry>
Complete stack trace:
Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.SimpleTextViewWindow.WpfTextViewHost.get()
Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.SimpleTextViewWindow.ClearCommandContext()
Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.VsMouseProcessor.PostprocessMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs e)
Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Utilities.WpfMouseProcessor.UIElement_MouseLeftButtonUp.AnonymousMethod__29()
Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Utilities.GuardedOperations.CallExtensionPoint(object errorSource = null, System.Action call)
Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Utilities.WpfMouseProcessor.UIElement_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
PresentationCore.dll!System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget)
PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target)
PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs)
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source = {Microsoft.VisualStudio.Text.Editor.Implementation.WpfTextView}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs}, bool reRaised = true)
PresentationCore.dll!System.Windows.UIElement.ReRaiseEventAs(System.Windows.DependencyObject sender = {Microsoft.VisualStudio.Text.Editor.Implementation.WpfTextView}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs}, System.Windows.RoutedEvent newEvent)
PresentationCore.dll!System.Windows.UIElement.OnMouseUpThunk(object sender, System.Windows.Input.MouseButtonEventArgs e)
PresentationCore.dll!System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget)
PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target)
PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs)
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source = {Microsoft.VisualStudio.Text.Editor.Implementation.SelectionAdornment}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs}, bool reRaised = false)
PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender = {Microsoft.VisualStudio.Text.Editor.Implementation.SelectionAdornment}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs})
PresentationCore.dll!System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs})
PresentationCore.dll!System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs args, bool trusted)
PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea()
PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs input)
PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport inputReport)
PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.ReportInput(System.IntPtr hwnd, System.Windows.Input.InputMode mode, int timestamp, System.Windows.Input.RawMouseActions actions, int x, int y, int wheel)
PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.FilterMessage(System.IntPtr hwnd = 0x000217b0, MS.Internal.Interop.WindowMessage msg = WM_LBUTTONUP, System.IntPtr wParam = 0x00000008, System.IntPtr lParam = 0x025f0247, ref bool handled = false)
PresentationCore.dll!System.Windows.Interop.HwndSource.InputFilterMessage(System.IntPtr hwnd = 0x000217b0, int msg = 0x00000202, System.IntPtr wParam = 0x00000008, System.IntPtr lParam = 0x025f0247, ref bool handled = false)
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd = 0x000217b0, int msg = 0x00000202, System.IntPtr wParam = 0x00000008, System.IntPtr lParam = 0x025f0247, ref bool handled = false)
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o)
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs)
WindowsBase.dll!MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(object source = {System.Windows.Threading.Dispatcher}, System.Delegate method, object args, int numArgs, System.Delegate catchHandler = null)
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs)
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd = 0x000217b0, int msg = 0x00000202, System.IntPtr wParam = 0x00000008, System.IntPtr lParam = 0x025f0247)
@sharwell
Copy link
Copy Markdown

If the handling is performed using an IMouseProcessor instead of an IOleCommandTarget, I'm fairly certain this situation would be avoided. Hopefully if he can track down which extension is using the IOleCommandTarget it could then be updated to use the new interface.

@sharwell
Copy link
Copy Markdown

Also, the code in VsMouseProcessor could be updated to check the IsTextViewHostAccessible property.

if (SimpleTextViewWindow != null && SimpleTextViewWindow.IsTextViewHostAccessible)
{
    SimpleTextViewWindow.ClearCommandContext();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment