Visual Studio 2015 Broken Razor Intellisense

C#asp.net MvcRazorIntellisenseVisual Studio-2015

C# Problem Overview


After installing and then repairing my VS2015 instance I still cannot get intellisense (server side) to work in my MVC views. I get alerted by message prompt as soon as I open for the first time in a session an .cshtml file and get addressed to the Activitylog file. Error message retrieved in ActivityLog.xml (short version):

> System.ArgumentException: Item has already been added. Key in > dictionary: 'RazorSupportedRuntimeVersion'

Here's the full version:

> System.Reflection.TargetInvocationException: Exception has been thrown > by the target of an invocation. ---> System.ArgumentException: Item > has already been added. Key in dictionary: > 'RazorSupportedRuntimeVersion' Key being added: > 'RazorSupportedRuntimeVersion' at > System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean > add) at System.Collections.Hashtable.Add(Object key, Object value) at > System.Collections.Specialized.HybridDictionary.Add(Object key, Object > value) at > Microsoft.VisualStudio.Utilities.PropertyCollection.AddProperty(Object > key, Object property) at > Microsoft.VisualStudio.Html.Package.Razor.RazorVersionDetector.Microsoft.Html.Editor.ContainedLanguage.Razor.Def.IRazorVersionDetector.GetVersion(ITextBuffer > textBuffer) at > Microsoft.Html.Editor.ContainedLanguage.Razor.RazorUtility.TryGetRazorVersion(ITextBuffer > textBuffer, Version& razorVersion) at > Microsoft.Html.Editor.ContainedLanguage.Razor.RazorErrorTagger..ctor(ITextBuffer > textBuffer) --- End of inner exception stack trace --- at > System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] > arguments, Signature sig, Boolean constructor) at > System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags > invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) > at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, > Binder binder, Object[] args, CultureInfo culture, Object[] > activationAttributes, StackCrawlMark& stackMark) at > System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, > Binder binder, Object[] args, CultureInfo culture, Object[] > activationAttributes) at System.Activator.CreateInstance(Type type, > Object[] args) at > Microsoft.Html.Editor.ContainedLanguage.Common.ContainedCodeErrorTaggerProvider'1.CreateTagger[T](ITextBuffer > textBuffer) at > Microsoft.VisualStudio.Text.Tagging.Implementation.TagAggregator'1.GatherTaggers(ITextBuffer > textBuffer)

If it's any help, I have some font-coloring customizations, and have the Web Essentials, Bundler & Minifier and Web Compiler extensions installed.

UPDATE: it happens either when I open an existing web application or when I create a brand new one from scratch. There's also an instance of VS2013 installed and running on the same machine.

No intellisense at all

As you can see from the pic above I get no intellisense at all, nor any kind of code coloring.

Any clue about how to fix it? Thanks in advance.

C# Solutions


Solution 1 - C#

This has been recurring for me also and seems to be connected to extension updates but I have not yet been able to blame anything specific. What I have been able to discover is a less intrusive resolution.

In my case deleting the contents of this directory allows the IDE to recover:

%LocalAppData%\Microsoft\VisualStudio\14.0\ComponentModelCache

Edit: I just came across this one which might be handy too - Clear MEF Component Cache (Open VSIX Gallery)

Solution 2 - C#

I solved this problem by resetting the user data

devenv.exe /resetuserdata

and remove the ".vs" folder in my project.


WARNING: this will reset all your user settings. Essentially, it is like resetting to factory defaults. You will lose any custom keyboard shortcuts, extensions you've installed etc.

Solution 3 - C#

FWIW, I had this problem with VS 2015 Enterprise on two different machines. On one machine, resetting user data made the problem go away (for a while). On the other machine, I had to totally uninstall and reinstall VS, and the problem went away for a while. On both machines, the problem came back after I installed an extension (once when installing Web Essentials, once when installing Git Diff Margin).

I burned an MSDN tech support case, and the answer was... Yeah, it's a bug, MS knows about it, and they're working on it.

Not a particularly actionable answer, but an answer nonetheless...

EDIT: And on the subject of working around the problem, I've encountered the problem a few more times since I posted this "answer". Most recently, I installed an update to NuGet Package Manager, and when VS restarted it started having this problem. I ran devenv.exe /resetuserdata, but that didn't help; it was still broken. So I tried again (ran devenv.exe /resetuserdata) and, bada bing bada boom, the problem went away (for now). The moral seems to be something along the lines of "if at first you don't succeed..."

Solution 4 - C#

Might have happened due to having ReSharper.

It will be fixed in future versions, but as of now (version 10.0.2), it is broken. ReSharper overrides the IntelliSense of Visual Studio and therefore it will not work, which also explains why running devenv.exe /ResetUserData fixes it since it removes ReSharper.

Manually return the IntelliSense power to VS through the menu:
ReSharper >> Enviroment >> IntelliSense >> Fill the following:
enter image description here

And this is how the IntelliSense from VS should look:
enter image description here

Solution 5 - C#

I met the same problem, but the cause was different from the other answers.

An update of Visual Studio (I suspect TypeScript update on September 2015) uninstalled the Web Developer Tools component of Visual Studio 2015. That causes IntelliSense not to work.

I installed Web Developer Tools in the installer options again AND deleted ComponentModelCache after the installation. That worked for me.

Solution 6 - C#

This fixed it for me right away.

In Visual Studio:

Click Tools->Options->Text Editor->All Languages->General Uncheck "Auto list members" Uncheck "Parameter information" Check "Auto list members" (yes, the one you just unchecked) Check "Parameter information" (again, the one you just unchecked) Click OK

Solution 7 - C#

To add my 2 cents. None of the previous solutions worked for me, then I found this link:

http://www.c-sharpcorner.com/blogs/how-to-resolve-intellisense-issue-in-visual-studio1

In particular this one

> Solution 4: > > Next, reset the Settings from the following location. > > Tools->Import and Export settings->Reset all settings.

From there I choose Visual C#

Solution 8 - C#

The /ResetUserData solution is your best bet, but I also think I have found out a possible cause of this...

I am currently using Umbraco to create Macro Partials in the BackOffice. When these files get created I click on the Hide/Show all files button to show the Macro Partial in my solution and the Razor Syntax Highlighting seems to stop working so my guess is new files introduced into your solution that aren't created directly through VS cause this issue.

Even when adding the files to the solution the Syntax Highlighting doesn't work.

Solution 9 - C#

Sometimes, the VS IDE does not show IntelliSense at all.

I just close the solution, close VS, then reopen it, and the problem is solved.

Solution 10 - C#

There is another solution, without reset all user data

(but only window layouts/toolbars):

close all VS2015 instances, [eventually backup, and] delete the folder:

"[User Directory]\AppData\Roaming\Microsoft\Visual Studio\14.0"

Now, re-open VS2015: layout was reset to factory preset, but Razor syntax would work

Solution 11 - C#

FYI: My VS 2015 PRO installation has full install with all 3-rd parties.

I tried all possible solution that here in article, it didn't help me. What Craig Goldensoph wrote helped me partially to find solution for me.

So first I did: Uncheck all checkboxes for Text Editor-> All Languages->General Statement completion: enter image description here

After Click OK- Reopen Option Dialog again: And check all for the same section: enter image description here

and apply settings again. You have to Restart your Visual studio. After restart it will take a time to load , but after that it worked for me.

Solution 12 - C#

If none of the other options work, there is a workaround. After entering the '.' operator, press the "Ctrl + Space" keys which should force the IntelliSense dialog to appear.

I was having this issue when working with .cshtml MVC razor files.

Solution 13 - C#

Mine was a slight pain in the keester but seemed to work. In my case it was a .aspx File that wouldn't do intellisense anymore (after I stupidly changed the .aspx filename...lesson learned!)

  1. I copied all my code out of the files (.aspx & .cs) into notepad for example.
  2. Deleted the .aspx file (which in turn deleted all child files).
  3. Saved my project. Created a new .aspx file with the same name.
  4. Copy/pasted my code from notepad.
  5. Saved it.
  6. Tried intellisense again. It worked!

Round about way but not as bad as uninstalling/vs reinstalling which is TOTALLY overkill. Good luck everyone! Hopefully MS will get this fixed one of these years!

Solution 14 - C#

This might sound funny but just to do one thing..

Put Breakpoint on any line and then wait for 5 seconds of that do not work then go to first line and put break point there and as you put break point it will ask for break point settings. enter image description here click on that settings and close that settings. Done. you intellisense is now working.

I have VS 2015 Community edition.Previously had VS 2015 Enterprise and it happened on that but after getting community i found that same happens and same solution work for both.

I found that solution by accidently during work.Also do that when project is not running.and you can remove that break point also.

Solution 15 - C#

You don't need to reset everything just remove all files from %LocalAppData%\Microsoft\VisualStudio\14.0\ComponentModelCache and restart VS, it'll be fine.

Solution 16 - C#

I've posted this answer on another SO question, just because I want to prevent people wasting the time I've just wasted. My problem was that I'd added files to a project, but not included them. So I chosen to show all files:

enter image description here

then chose to include folders:

enter image description here

The problem only shows up when you open an MVC website as a project, and not when you open it as a website directly.

Solution 17 - C#

I was only able to fix this by updating the webpages version, which I mentioned in another similar question:

https://stackoverflow.com/questions/31644895/razor-intellisense-not-working-in-vs-2015/40115477#40115477

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCristian MerighiView Question on Stackoverflow
Solution 1 - C#brahnpView Answer on Stackoverflow
Solution 2 - C#YanosView Answer on Stackoverflow
Solution 3 - C#Bob.at.Indigo.HealthView Answer on Stackoverflow
Solution 4 - C#NucSView Answer on Stackoverflow
Solution 5 - C#WakuseiView Answer on Stackoverflow
Solution 6 - C#Craig GoldensophView Answer on Stackoverflow
Solution 7 - C#AlexanderDView Answer on Stackoverflow
Solution 8 - C#ChronixPsycView Answer on Stackoverflow
Solution 9 - C#Thomas.BenzView Answer on Stackoverflow
Solution 10 - C#T-motyView Answer on Stackoverflow
Solution 11 - C#Eugene BosikovView Answer on Stackoverflow
Solution 12 - C#ColinView Answer on Stackoverflow
Solution 13 - C#John WaclawskiView Answer on Stackoverflow
Solution 14 - C#JayView Answer on Stackoverflow
Solution 15 - C#Nilesh MoradiyaView Answer on Stackoverflow
Solution 16 - C#Andy BrownView Answer on Stackoverflow
Solution 17 - C#TonyView Answer on Stackoverflow