1

Topic: InvalidOperationException for solution with file opened

Getting System.InvalidOperationException in ViEmu 3.7.6 and Visual Studio 2017 (15.9.3). Steps to reproduce:
- create new solution in Visual Studio, open any file in it and close Visual Studio without closing the editor.
- try to load this solution in Visual Studio. On solution load VS is trying to open the editor with file that was left opened and shows exception alert.

System.InvalidOperationException: "GetTextViewLineContainingBufferPosition called before view is fully initialized."

Call Stack (truncated):
   Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Editor.Implementation.WpfTextView.Microsoft.VisualStudio.Text.Editor.IWpfTextView.GetTextViewLineContainingBufferPosition(Microsoft.VisualStudio.Text.SnapshotPoint bufferPosition)
Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Editor.Implementation.WpfTextView.GetTextViewLineContainingBufferPosition(Microsoft.VisualStudio.Text.SnapshotPoint bufferPosition)
Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.MultiSelection.Implementation.SelectionUIProperties.TryGetContainingTextViewLine(out Microsoft.VisualStudio.Text.Formatting.ITextViewLine line)
Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.MultiSelection.Implementation.SelectionUIProperties.ContainingTextViewLine.get()
Microsoft.VisualStudio.Platform.VSEditor.dll!Microsoft.VisualStudio.Text.Editor.Implementation.CaretElement.ContainingTextViewLine.get()
VSHub.dll!VSHub.ViEmuCaret.CalcCaretSize()
VSHub.dll!VSHub.ViEmuCaret.SetCaretType(nglib.ViCaretShape caret)
VSHub.dll!VSHub.ViEmuCaret.Initialize(VSHub.ViEmuView _qView)
VSHub.dll!VSHub.ViEmuView.InitializeWpfInterfaces()
VSHub.dll!VSHub.ViEmuViewManager.TextViewCreated(Microsoft.VisualStudio.Text.Editor.IWpfTextView qTextView)

2

Re: InvalidOperationException for solution with file opened

I got this one too.  ViEmu VSIX version is 3.7.6, but the settings box shows v3.8.0 (not sure if that means anything or not).  Update to VS2017 15.9.4 also exhibits the problem.  I've tried disabling other editor extensions and just leaving ViEmu enabled, but it still throws the dialog.

Here's the pertinent entry from the ActivityLog.xml file:

System.InvalidOperationException: GetTextViewLineContainingBufferPosition called before view is fully initialized.&#x000D &#x000A
   at Microsoft.VisualStudio.Text.Editor.Implementation.WpfTextView.Microsoft.VisualStudio.Text.Editor.IWpfTextView.GetTextViewLineContainingBufferPosition(SnapshotPoint bufferPosition)&#x000D &#x000A
   at Microsoft.VisualStudio.Text.Editor.Implementation.WpfTextView.GetTextViewLineContainingBufferPosition(SnapshotPoint bufferPosition)&#x000D &#x000A
   at Microsoft.VisualStudio.Text.MultiSelection.Implementation.SelectionUIProperties.TryGetContainingTextViewLine(ITextViewLine&amp line)&#x000D &#x000A
--- End of stack trace from previous location where exception was thrown ---&#x000D &#x000A
   at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)

3

Re: InvalidOperationException for solution with file opened

Also seeing this.

Haven't seen any response on the forum here for quite some time. Is ViEmu dead? (hope not)

4

Re: InvalidOperationException for solution with file opened

Looking into this, apologies for the delay in responding, too many things fighting for my attention. Will post back soon. Cheers - Jon

5

Re: InvalidOperationException for solution with file opened

I have built a new version fixing this. The initialization ViEmu does when a new text view is created (for example, when a source file is opened), includes retrieving the font size at the cursor position, to create a caret of the right size. Stating with a recent update of VS2017, the view is not fully initialized when this "TextViewCreated" notification is sent out to plug-ins such as ViEmu, and thus some operations can fail. ViEmu does have a try/catch block around the whole thing to avoid issues, but even then, VS decides to report it to the user. The new version checks whether the view is fully initialized (basically, whether the formatted text info is actually available).

I will probably release this officially on the weekend, but here is a link for you to download and test meanwhile:

http://www.viemu.com/ViEmuVS2013-2017_3.8.1.vsix

It also includes some minor improvements to :s command compatibility and related find/substitution operations (namely, :s//xyz will use the last searched-for regex for the substitution).

Apologies for the delay and hope this fixes it for you.

Regards,

  -- Jon

6

Re: InvalidOperationException for solution with file opened

Jon - looks good now.

The new search/replace behavior is extremely useful - been wanting that for ages, thanks!

7

Re: InvalidOperationException for solution with file opened

Thanks Jason, great to hear it works well for you! -- Jon