ChatGPT解决这个技术问题 Extra ChatGPT

Visual Studio 2015 Broken Razor Intellisense

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.

https://i.stack.imgur.com/W1Waz.jpg

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.

Try starting a new web project using the default web template. If it is working then the issue is related to your project. At least it is easier to narrow it down.
Sorry Rosdi, I had to provide more details. I updated the text above accordingly. BTW, keeping googling I just found an open feedback here connect.microsoft.com/VisualStudio/feedback/details/1579142/… which reports my exact same issue.
Hi Knerd, fact is that I get no intellisense at all (see pic above). Feels to me more like a core visual studio issue than some wrong project settings (I get the very same issue in the default template views of a brand new project).
This is how I fixed a very similar issue in VS 2015 RTM: stackoverflow.com/a/32308899/1551276

b
brahnp

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)


ResetUserData had worked for me, but the issue returned. This works and is much less intrusive (no need to restore all your extensions).
This worked for me without running devenv.exe /resetuserdata
This worked for me as well. I tried the resetuserdata command first, but that didn't seem to do anything. This worked right away!
It worked for me, it happened several times, and i always reseted the user data and it's awful, i use the Roaming Extension Manager to make it more simple to reinstall the extensions
Did not fix the issue in VS2015 Professional. Razor syntax highlighting and intellisense still do not work. No errors are displayed.
t
testpattern

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.


I didn't need to remove the .vs folder for this to fix my issue. resetuserdata was enough
Just make sure you run that from this folder "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\" specially if you have more than one VS installed on your computer.
For me devenv.exe /resetuserdata did not fix the issue! FYI: I dont get any errors but VS does not paint syntax for Razor views.
Be aware that you will lose all your Visual Studio settings like extensions and credentials (of the account you're signed in)! VS must be closed before you run devenv.exe /resetuserdata.
Before you use this command, know what it does. Aside from minor inconveniences such as logging you out of Visual Studio and reseting your windows, it also uninstalled several extensions and Resharper. Finding the correct versions to reinstall took longer than I expected.
B
Bob.at.Indigo.Health

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..."


Some warning that this wipes away absolutely everything would be useful. My panel configuration is gone, my syntax highlighting is gone and the problem is still not fixed. :( How do I get my data back?
P
Pang

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.

https://i.stack.imgur.com/5YZCt.png

https://i.stack.imgur.com/LjgMb.png


P
Pang

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.


This solved the problem for me as well. When doing a repair on VS2015 via add/remove programs, I could see that Web Developer Tools wasn't even installed. Checking the box and completing worked.
C
Craig Goldensoph

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


Tried resetuserdata, delete vssc, clear componentcache and didn't work. After i tried this and It's Worked! Thank you
C
Community

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#


C
ChronixPsyc

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.


Interesting, as I'm experiencing this with Umbraco as well.. Umbraco 7.4.3 and VS 2015, specifically..
T
T-moty

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


E
Eugene Bosikov

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.

https://i.stack.imgur.com/ZDu6Z.png

https://i.stack.imgur.com/RmPQu.png

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.


Common problem. What I read everybody had similar issues and it was always fixed in different way. I just shared what helped for me. Sorry, could not be solution for everybody.
P
Pang

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.


P
Pang

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.


J
Jay

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

https://i.stack.imgur.com/kbRMM.png

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.


N
Nilesh Moradiya

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.


A
Andy Brown

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:

https://i.stack.imgur.com/6ONYm.jpg

then chose to include folders:

https://i.stack.imgur.com/pF3F7.jpg

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


C
Community

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

Razor intellisense not working in VS 2015


J
John Waclawski

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!)

I copied all my code out of the files (.aspx & .cs) into notepad for example. Deleted the .aspx file (which in turn deleted all child files). Saved my project. Created a new .aspx file with the same name. Copy/pasted my code from notepad. Saved it. 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!


关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now