Bug 47188 - ITextBufferExtensions.GetFilePath fails with KeyNotFoundException
Summary: ITextBufferExtensions.GetFilePath fails with KeyNotFoundException
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: General ()
Version: 4.2.0 (C8)
Hardware: PC Windows
: Highest blocker
Target Milestone: 4.3.0 (C9)
Assignee: Adrian Alonso
: 44588 ()
Depends on:
Reported: 2016-11-17 15:38 UTC by Magnus Johansson
Modified: 2017-01-16 11:15 UTC (History)
10 users (show)

Is this bug a regression?: ---
Last known good build:

ide.log (3.85 KB, text/plain)
2016-11-17 15:38 UTC, Magnus Johansson
ContentView that also fails (314.47 KB, image/png)
2016-12-28 19:03 UTC, Clint

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Magnus Johansson 2016-11-17 15:38:15 UTC
Created attachment 18508 [details]

The previewer fails with this exception:

Xamarin.VisualStudio.Forms.Previewer.PreviewerToolWindow Error: 0 : [2016-11-17 16:27:50.3405] Unexpected exception trying to swap text buffers for the Xamarin.Forms previewer
System.Collections.Generic.KeyNotFoundException: key
   at Microsoft.VisualStudio.Utilities.PropertyCollection.GetProperty(Object key)
   at Microsoft.VisualStudio.Text.ITextBufferExtensions.GetFilePath(ITextBuffer textBuffer) in c:\data\lanes\3513\47830f6b\source\xamarinvs\src\Features\VisualStudio.Forms.Previewer\ITextBufferExtensions.cs:line 75
   at Xamarin.VisualStudio.Forms.Previewer.PreviewerToolWindow.<>c__DisplayClass42_0.<ActiveDocumentChanged>b__0(ITextView t) in c:\data\lanes\3513\47830f6b\source\xamarinvs\src\Features\VisualStudio.Forms.Previewer\PreviewerToolWindow.cs:line 290
Comment 1 Alan McGovern 2016-11-18 11:13:32 UTC
/cc some more eyes

This is a recurring problem which has no explanation. Is there a better way of gathering filepath/textbuffer information?
Comment 2 Alan McGovern 2016-11-23 10:15:21 UTC
Any ideas on what could cause this? It's been happening for months but it's in VS specific code and there's no obvious sign of what's going wrong;.
Comment 3 Alan McGovern 2016-12-20 11:51:22 UTC
Marking this as highest/blocker for C9 so we can get some eyes on this.
Comment 4 Clint 2016-12-28 19:03:52 UTC
Created attachment 19018 [details]
ContentView that also fails

Even a simple content view that can find the static resource (as evidenced by the matching blue underline for "Blue4") fails the Previewer for not being able to find the static resource by key "Blue4".

See attached "PreviewerFail.png" for example of how the resource is being defined in the Aplication.Resources and how the ContentView is referencing it.
Comment 5 Alan McGovern 2017-01-04 10:08:14 UTC
Clint, that is a separate issue which needs to be filed separately. Can you file a new bug which includes the log files, and if possible a small sample which reproduces the issue. This is something which should work as part of the latest C9 alpha releases.
Comment 6 Alan McGovern 2017-01-04 10:09:21 UTC
This issue is a general issue with the VS integration and not something intrinsic to the forms previewer. I'm changing the component just so more eyes are put on this.
Comment 7 Jose Gallardo 2017-01-04 12:52:10 UTC
Hi Magnus, 

This bug should be already fixed, and included in current Alpha channel bits.
I'm marking it as resolved/fixed.

However, if you're still facing it with latest **ALPHA** preview, please reopen the bug and share with us the following information:

1. Xamarin Logs
Go to the menu "Help - Xamarin - Zip Logs". Please attach that zip file to the bug report.

2. Environment information
Go to the menu "Help - About Microsoft Visual Studio" and press "Copy Info". Please paste that info into a Bugzilla comment.

Also, it would also be great if you can share with us some sample xaml that fails or repro steps, and what kind of project structure are you using (if it's with a Shared project or a PCL), if it does fail for either iOS or Android previewer and the Xamarin.Forms version used.

Comment 8 Gonzalo Martin 2017-01-04 17:58:44 UTC
Verified. Forms Previewer is working fine with static resources like attached image shows (no exceptions thrown)

Environment detail:

Xamarin (ff6c133)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android (4ce2ebd)
Visual Studio extension to enable development for Xamarin.Android.

Xamarin.iOS (0366d84)
Visual Studio extension to enable development for Xamarin.iOS.
Comment 9 Alan McGovern 2017-01-05 12:59:14 UTC
Reopening as this is still happening. It was just reported in this bug: https://bugzilla.xamarin.com/show_bug.cgi?id=51232#c1

This issue is somewhat random so it's hard to verify.
Comment 10 Alan McGovern 2017-01-05 13:02:37 UTC
The extract from the logs there is:

Xamarin.VisualStudio.Forms.Previewer.PreviewerToolWindow|Error|0|Unexpected exception trying to swap text buffers for the Xamarin.Forms Previewer
System.Collections.Generic.KeyNotFoundException: key
   at Microsoft.VisualStudio.Utilities.PropertyCollection.GetProperty(Object key)
   at Microsoft.VisualStudio.Text.ITextBufferExtensions.GetFilePath(ITextBuffer textBuffer) in C:\d\lanes\3012\f4082803\source\xamarinvs\src\Features\VisualStudio.Forms.Previewer\ITextBufferExtensions.cs:line 75
   at Xamarin.VisualStudio.Forms.Previewer.PreviewerToolWindow.<>c__DisplayClass40_0.<ActiveDocumentChanged>b__0(ITextView t) in C:\d\lanes\3012\f4082803\source\xamarinvs\src\Features\VisualStudio.Forms.Previewer\PreviewerToolWindow.cs:line 282
Comment 11 Alan McGovern 2017-01-06 12:31:01 UTC
*** Bug 44588 has been marked as a duplicate of this bug. ***
Comment 13 Gonzalo Martin 2017-01-13 20:22:44 UTC
Verified again and I could not reproduce the static resource issue. This bug will be closed.

Environment info: https://gist.github.com/gonzalonm/49c49e1f59fd2f7b9876f21590233875
Comment 14 Alan McGovern 2017-01-13 21:39:31 UTC
Just to clarify - static resources have nothing to do with the issue the bug was addressing.