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)
@hmemcpy
Copy link
Copy Markdown
Author

hmemcpy commented Mar 9, 2014

This happens on my machine, where I have a bunch of VS extensions installed, after performing a Ctrl-Click navigation TWICE with ReSharper. Upon navigating to the 2nd type, I get a messagebox saying there was an error in one of the exceptions. Visual Studio keeps working fine.

It's NOT caused by ReSharper, because when JUST ReSharper installed, I get no error. Must be something else.

@sharwell
Copy link
Copy Markdown

sharwell commented Mar 9, 2014

The problem is caused by an IOleCommandTarget implementation which registered with IVsTextView by calling IVsTextView.AddCommandFilter. In the implementation of IOleCommandTarget.Exec, the command ID VSStd2KCmdID.ECMD_LEFTCLICK or VSStd2KCmdID.DOUBLECLICK is being handled.

I would open ILSpy, and open the assemblies contained in %USERPROFILE%\AppData\Local\Microsoft\VisualStudio\12.0\Extensions (recursively). I would then open Microsoft.VisualStudio.OLE.Interop.dll and locate the IOleCommandTarget interface. You can then examine the derived types from that interface for a class whose Exec method handles the commands listed above. Selectively disable the associated extension(s) until you narrow down the culprit.

@jaredpar
Copy link
Copy Markdown

I'd argue this is just a straight up bug in Visual Studio. Either the SimpleTextViewWindow or VsMouseProcessor class simply aren't properly accounting for the fact that the IWpfTextView could be closed at this point and is throwing.

I'm looking at the decompiled code for 2013 and I can't 100% see where this is happening. But the code path does seem to not be accounting for this possibility

@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