43

In VS 2015, only when in Razor (.cshtml) files, roughly half of the time the autocomplete/suggestion list/intellisense doesn't work correctly (sorry, not sure the actual term... when you type an object and hit . and the list of properties and methods shows to select from)

The behavior is that when I hit ., the list popups up for a fraction of a second and then closes. It happens so fast I try to do a quick Backspace, ., Backspace, . cycle a few times to at least see the name I need, but I usually cant' get it and end up having to find the exact name elsewhere from code. Extremely irritating...

It happens sporadically with no real pattern I can find. Here's patterns that I've ruled out:

  • The file that's open doesn't seem to matter.
  • Whether or not I close/reopen the file doesn't seem to matter
  • Whether I navigate to another file and back doesn't seem to matter
  • It will work/not work multiple times on and off throughout the same file
  • It doesn't seem to be relevant to any particular object/property/method

I've checked all my options (there doesn't seem to be Text Editing options for Razor?), have tried clearing caches, the reloading solution/projects, restarting VS, all of which seem to still provide no pattern.

Has anyone come across this and have any ideas of where else I can look to fix it?

Example Here's an extremely simple example... new project, very little code/files, very simple view. Where the Model. stops, I should have the usual base methods, and an 'Items' collection. It pops up for a split second then disappears... no lambdas/complex view parsing involved (this is reproducible as well):

enter image description here

Update: Patterns

Things I've noticed:

  • If I'm entering a @model ns.ns.ns.type, it rarely happens toward the "base" end of the namespaces. It's as I get further towards the type that it happens. This one is intermittent.
  • In some cases, it works perfectly fine, every single time. For example, I often use DevExpress tools, and have never seen the behavior on any of their extensions (so, @Html.DevExpress(). (and other similar, not necessarily DevEx models) will never cause a problem)
  • It happens almost all the time when I'm accessing my @Model (which is where I most want it!). I've found some cases where this is reproducible every time (see above example), but it's about 90%+
  • Occasionally, as I work through the object tree, one will fail while the next works (ex: @models ProjName.Web.App.Subscriptions.Models.AccountCreateVM... it might fail on Subscriptions but work fine on Models)
  • Occasionally, beginning to type the name within autocomplete kicks it back into gear and it starts working again. In the above example, starting to type Acc for AccountCreateVM causes it to start working again.
jleach
  • 7,410
  • 3
  • 33
  • 60

8 Answers8

21

I haven't found the root cause, but in all cases, CTRL+SPACE works. This isn't the best, but light years better than nothing at all.

(this shortcut is not one I've used in the past, so this is likely standard behavior, but...) If you're at the dot Model. and autocomplete list disappears, CTRL+SPACE consistently brings it back up, and when it does come back, it stays! If there's only one possible autocomplete member, it'll auto-fill the member for you upon CTRL+SPACE

jleach
  • 7,410
  • 3
  • 33
  • 60
  • 3
    This does help, but as soon as I type the next character, the intellisense drop-down disappears again. – Ross Brasseaux Dec 01 '16 at 19:27
  • @Lopsided - use the arrow keys to go down to the item you need, that should keep the dropdown open (usually only a few items in the list, so fairly workable). – jleach Dec 01 '16 at 19:45
  • I finally used ``CTRL+SPACE`` the kept **arrow key** pressed to prevent the dropdown to disappear – Fabrice T Oct 06 '17 at 08:12
  • Carter Medlin posted the solution. solved the problem by installing the latest version Microsoft ASP.NET and Web Tools. Visual Studio under Tools->Extensions and Updates...->Updates->Visual Studio Gallery – AlejandroDG Aug 08 '19 at 15:42
20

This happens for me all throughout VS2015 during lambda statements.

It happens when editing code "mid-document", as in, if there is anything besides a ) or } following where I'm typing. VS appears to be struggling to tell where the current statement ends & the next statement begins.

The following code will consistently fail to trigger Intellisense at the period, even when explicitly invoked.

var subset = initialSet.Where(x => x.
var result = new Whatever();

In Razor, it is very common to be editing code between existing text and using lambda statements:

<strong>@Html.DisplayFor(m => m.</strong>

This is probably why you only experience this in Razor.

The way I work around this bug is just to write the ) to close the method.

var subset = initialSet.Where(x => x.)
var result = new Whatever();

<strong>@Html.DisplayFor(m => m.)</strong>

Intellisense can then be triggered on the period.

If you're using a method that requires a minimum of more than just the lambda (like RadioButtonFor), you'll also need to put in a comma for each of the extra parameters.

<strong>@Html.RadioButtonFor(m => m.,)</strong>

If Intellisense is appearing, but immediately disappearing again, the best solution I've found so far is to just type a few letters of any known member, then using Ctrl-Left to skip back to the period, and trigger Intellisense again (Ctrl-Space or backspace-retype). This usually gets it to appear and stay. You'll have to delete the characters you typed afterwards, which can be frustrating.

friggle
  • 3,362
  • 3
  • 35
  • 47
  • I have been noticing emerging patterns, and a good portion is in lambdas (which are rampant in razor), but that's not the only place. For example, one of first things I type in an empty view is the _@model ns.web.models.model_ and it can't get past the first namespace. I'll keep filing notes on my end and may someday even get an answer, but this is a good part of it, I think. – jleach Apr 20 '16 at 14:00
  • 2
    I'm alarmed at how this bug can be so widespread and repeatable, yet not only did it make it into release, but it still hasn't been fixed even though VS2015 is on Update 2. – friggle Apr 20 '16 at 14:27
  • 3
    Is there anything we should do to speed up the fixing of this bug? I am having the same issue - this partially works (deleting the bracket first) but I have to back space the dot once to get the intellisense list to remain visible. Usually it only happens in lamdas but it happens occasionally elsewhere. I like doing things quickly and intellisense is very important for that - especially the auto-complete. – Cheesus Toast Jun 09 '16 at 14:14
  • 4
    Did you know that instead of deleting the dot and retyping, you can press `ctrl` + `space` to open the Intellisense? – wf4 Jul 26 '16 at 14:30
  • 2
    wf4's solution works - at least until they fix it (2018?)! – Chris Nevill Jul 28 '16 at 16:25
  • What's described in this answer is a common issue in VS and easily solved, but it's not what the OP is asking (I can tell because I have the same problem as the OP). AFAIK the intellisense disappearing problem only happens inside a Razor view (mind the word 'disappear' i.e. it has to appear/trigger first and then vanish). It can happen with or without the closing parentheses and brackets. Really weird. – Francisco Sep 07 '16 at 17:10
  • @Francisco I added a trick for dealing with the 'disappearing' Intellisense. – friggle Sep 08 '16 at 15:21
  • @friggle yes I know about that trick, I've been using it for about a year, but it's really annoying to have to use it =/ The worst part is that I usually just type in a few characters then inmediately after that I press 'enter' or 'tab' or 'space' (muscle memory, really) expecting VS to autocomplete the property or method or we, but it's too late because the windows has already disappeared so I have to ctrl+Z my way out of it. If at least it were more consistent, I would try to predict the bug. Sadly, it's not... – Francisco Sep 08 '16 at 20:45
14

Just make sure the ) does not touch the text you are editing, and the popup will stay up.

Instead of...

@Html.Partial("ManageGrid", Model.)

Use...

@Html.Partial("ManageGrid", Model. )

The intellisense seems to get confused by touching close parenthesis. Not ideal, but this was the only way I could get it to work for me consistently.

Carter Medlin
  • 11,857
  • 5
  • 62
  • 68
  • This problem goes away and then comes back like a bad penny (English expression). I'll try to remember this nice simple workaround! – Andy Brown Aug 21 '17 at 08:50
4

In my specific case, i was able to solve the problem by installing the latest version Microsoft ASP.NET and Web Tools.

https://marketplace.visualstudio.com/items?itemName=JacquesEloff.MicrosoftASPNETandWebTools-9689

Once I installed it, the problem was gone. It is likely that this update fixed something that could be fixed with an older version, but either way I'm happy.

(I found this in Visual Studio under Tools->Extensions and Updates...->Updates->Visual Studio Gallery)

Carter Medlin
  • 11,857
  • 5
  • 62
  • 68
3

I had the same error and I fixed it by deleting all the files of the component model cache.

This is the path:

Users\YourName\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache

Hope that helps

tocqueville
  • 5,270
  • 2
  • 40
  • 54
1

I use ctrl+j as a temporary solution when I know the content.

Or keep writing without right parenthesis can use the completion:

@Html.LabelFor(m => m.Name

lgt945
  • 19
  • 3
-1

Whenever this annoying thing happens to me, I just put an extra dot and then it works. I have to put the extra dot every time. For example, if I write this and intellisence flashes and disappears:

@Html.TextBoxFor(m => m. 

then I just do this:

@Html.TextBoxFor(m => m..

And intellisense will now show after first dot. I have made this a habit until MS has a fix for it.

CodingYoshi
  • 25,467
  • 4
  • 62
  • 64
-1

Instead of...

@Html.Partial("ManageGrid", Model.)

Use...

@Html.Partial("ManageGrid", Model.
Tom McDonough
  • 1,176
  • 15
  • 18