24

When I load up my VS2013 projects in 2015, all my razor views are filled with red squiggly underlines.

@model, @Scripts @url, @Html.Partial, lambda expressions

Intellisense is now fairly useless as it seems to be missing half the options.

Solutions I've seen involved deleting .vs folder, and devenv.exe /ResetUserData, however these don't work for me.

I'm on a fresh install of VS 2015 Community using the same install files as my colleagues. None of them have the razor issues, and they're working on the same projects as I am.

Any idea how to fix this?

Edit...Further Info! I uninstalled/reinstalled VS 2015 Community, opened my projects, and the razor worked! I then clicked on a notification saying to update NuGet. NuGet update installed, VS restarted, razor stopped working again. So the NuGet update is breaking razor??

Every time I open a razor file it says "An exception has been encountered. This may be caused by an extension. You can get more information by examining the file 'C:\Users\Jonathan\AppData\Roaming\Microsoft\VisualStudio\14.0\ActivityLog.xml'. "

In the activity log I get the following error

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

How do I fix this?

mejobloggs
  • 7,937
  • 6
  • 32
  • 39
  • 2
    I have the same issue, I had to go back using VS 2013... – Guigui Jul 27 '15 at 13:51
  • Bizarre. I've read quite a few people with this problem but no solutions for some. Some projects I open work perfectly fine but most don't. Yet for my colleagues they all work properly. I've switched back to VS 2013 for everything that doesn't work in 2015 :( – mejobloggs Jul 27 '15 at 20:54
  • 1
    On my machine, everything WAS working fine on VS2015 even with CodeDom compilers. Then, all of a sudden, I started to get the "System.Reflection.TargetInvocationException..." error on load of a script in the UI. Everything continued to compile and work fine, I just can't operate like this. I am retracing my steps to see if any extension is causing this, but it's incredibly frustrating and unproductive! – HumbleBeginnings Aug 02 '15 at 21:28
  • 1
    Did a complete repair on VS2015 Professional. Can't even get a brand new project to show Razor with no extensions installed! Arrgghh! – HumbleBeginnings Aug 02 '15 at 23:45
  • possible duplicate of [Visual Studio 2015 Broken Razor Intellisense](http://stackoverflow.com/questions/31581666/visual-studio-2015-broken-razor-intellisense) – Mormegil Sep 11 '15 at 12:00
  • Possible duplicate of [Visual Studio 2015 not syntax highlighting razor nor Intellisense](http://stackoverflow.com/questions/30311355/visual-studio-2015-not-syntax-highlighting-razor-nor-intellisense) – fabriciorissetto Nov 17 '15 at 13:11

14 Answers14

22

You dont need to reset the entire configurations of your Visual Studio using the devenv.exe /ResetUserData to workaround this

Instead of it, try to just delete the contents of this directory with Visual Studio closed then reopen it: %LocalAppData%\Microsoft\VisualStudio\14.0\ComponentModelCache

fabriciorissetto
  • 9,475
  • 5
  • 65
  • 73
14

Here's what FINALLY worked for me: Start -> Run -> (Or Windows Key + R) Then type "devenv.exe /resetuserdata" (no quotes of course)

I did not have to delete the .vs file, as some others had experienced.

See also: Visual Studio 2015 Broken Razor Intellisense

Community
  • 1
  • 1
HumbleBeginnings
  • 1,009
  • 10
  • 22
  • 4
    Didn't work for me unfortunately. I mentioned in the original post that I'd tried both resetuserdata and deleting the .vs :( – mejobloggs Aug 03 '15 at 00:04
  • 1
    I'm sorry - I didn't see that in your OP -- I must have been going crazy. Just to confirm from my end -- I "did" the full repair, but don't think that was the issue. Also just in case make sure that VS is closed when you reset your environment. I don't think it's case sensitive but might be worth another try. Lastly - have you confirmed that your old devenv was renamed in "C:\Users\(username)\AppData\Roaming\Microsoft\VisualStudio" ? Interestingly, what was renamed was my VS2013 I think. Not trying to belabor your pain, just trying to help, my friend. :) It is FRUSTRATING! – HumbleBeginnings Aug 03 '15 at 00:13
  • I kind of have to apologize for upvoting this answer since the OP did say he tried this, but it worked for me, so thanks for the reminder to try it. Good luck @mejobloggs :\ – pbristow Aug 27 '15 at 14:33
  • This will work if Intellisense craps out completely. it won't help intellisense not working for razor. still worth an upvote. – Timothy Groote Oct 16 '15 at 11:27
  • Did not fix the issue in VS2015 Professional. Razor syntax highlighting and intellisense still do not work. No errors are displayed. – Justin Skiles Oct 28 '15 at 15:51
  • I'm running VS2015 Pro and this fix has saved my bacon at least 3-4 times. It's a pain to have to do - so much so that I now have a list of extension re-installs to ease the pain somewhat when I have to do it. Sorry this didn't work for you... :( – HumbleBeginnings Oct 28 '15 at 16:00
  • Well it resets a lot of your dev environment and removes installed extensions, but it gives you back Razor intellisense. Not the perfect solution necessarily but it gets you back in the saddle quickly. – HumbleBeginnings Nov 25 '15 at 00:35
  • Thank you so much! This has been my issue for months now. Every time MS did an update on VS I had to reinstall it. It was driving me nuts. I thought it was from everything from antivirus software to a web proxy causing my issues. fyi.. i did find it easier to disable my antivirus software while updating. Not a great practice but it is a dev machine. – Spencer Mar 31 '16 at 18:05
  • 1
    @SpencerK You're welcome! Curious - are you saying that disabling your AV eliminated the problem sometimes? Not aware of that but if so it's good to know. As I mentioned before (I think) that I actually have a little cheat sheet that I use that is full if keyboard shortcuts that help re-setup my environment when I have to resort to using this fix. I would be far better for MS to find the issue and fix it (or tell us what is causing it) but at least it's better than reinstalling! Cheers! – HumbleBeginnings Mar 31 '16 at 18:11
  • @HumbleBeginnings i would do a complete reinstall to fix the issue if the repair didn't work. The problem persisted against multiple users on the same machine so i thought it could be the antivirus. So once i disabled the AV and did a repair it worked. I dont have enough tests to prove that it made a difference tho. It's my default action when doing a install that had a problem. Old tech support habit i suppose. – Spencer Apr 11 '16 at 23:47
  • @SpencerK -- when you say a "repair" do you mean from Program Install/Repair? If so - do you still have to restore all of your environment settings as well? I'm not sure if possibly you missed some of my posts but the devenv.exe /resetuserdata always has worked perfectly for me, other than having to restore my environment settings... – HumbleBeginnings Apr 12 '16 at 00:00
  • @HumbleBeginnings - Yes and Yes, i was doing the Program Install/Repair to reset my user settings. if that didnt work i would do a complete uninstall / install of Visual Studio. It was a lengthy process – Spencer Apr 12 '16 at 15:28
5

I've upgraded to mvc5 and so forth to razer 3. It solved my issue.

I followed this instructions :

http://www.asp.net/mvc/overview/releases/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-21

Guigui
  • 1,105
  • 1
  • 11
  • 21
  • I just wanted to say that I followed the guide, line by line, and it worked for me, even after I tried some of the devenv.exe commands suggested here. I've had the issue for a good few months now and I'm just happy that I finally got it resolved. – Shafiq Jetha Dec 22 '15 at 02:03
5

Had the same issue. ResetUserData didn't work, etc. What ResetUserData did do though was reset some of the dialogs that were suppressed. Ultimately a dialog popped up stating "The 'CompatiblityCheckerPackage' did not load correctly." It told me to go to my users folder (path below) and check out the ActivityLog.xml. Turns out WebEssentials 2015 did not install correctly and was failing to load. I installed WebEssentials again and the Intellisense errors went away.

Full Path for me:

C:\Users\xxx\AppData\Roaming\Microsoft\VisualStudio\14.0\ActivityLog.xml

Hope this helps.

Rusty
  • 51
  • 1
  • 3
5

This could fix similar problems (I got it from somewhere, unfortunately I cannot remember, on Github)

  • Close VS Studio
  • Run command prompt as Administrator
  • In command prompt:
    > cd "%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\Common7\IDE"
    > devenv /updateconfiguration
    > devenv /clearcache
    
    I hope the above will be helpful to someone.
Pranithan T.
  • 323
  • 1
  • 6
  • 14
zinczinc
  • 544
  • 5
  • 11
  • answer worked for me :) followings are the clean & clear 3 lines of code those I run in cmd. `C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE>` `C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE>devenv /updateco nfiguration` `C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE>devenv /clearcac he` – Nadir Dec 17 '15 at 06:48
3

Deleting the entire Solution and re-downloading it from Source Control is the only thing that worked for me. You might need to open the solution in VS 2013 first before you can open it in 2015... a very buggy Visual Studio release Microsoft!

Edit: Another thing that is strange, at least for me... deleting the red zigzag underlined text then retyping it fixed the problem! Possibly just a random thing that happened to me.

Serj Sagan
  • 28,927
  • 17
  • 154
  • 183
3

I had same issue and none of these answers worked. What I finally saw was, my Views web.config file was referencing MVC 4, and my main web.config was referencing MVC 5. So I could compile fine but intellisense wasn't working. MVC 4 isn't supported in VS2015. Why my web.config files were different I don't know. When I updated MVC in VS2012 months ago it must not have updated that config file.

Clarke76
  • 724
  • 1
  • 7
  • 17
  • Thanks! This was just what I needed. I had assumed this was a web.config issue but hadn't thought to check the web.config file inside the Views folder! :) Cheers – Brendan Nov 12 '15 at 20:06
3

You don't to update anything.
Just delete component cache from this folder C:\users\xxx\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache And ot will work fine . Try it

Amjad
  • 31
  • 1
  • In Visual Studio 2017 (Enterprise) I did something akin to this. In my case, there were several folders prefixed with "15.0" ... in the folder "C:\Users\xxx\AppData\Local\Microsoft\VisualStudio\15.0_a895a793" I found the ComponentModelCache folder, deleted it, opened VS and I was back up and running. Thank you!!! – Bob Tabor Apr 07 '17 at 11:08
1

None of these solutions fixed it for me. What worked was ensuring my webpages version was up to date. So

<add key="webpages:Version" value="3.0.0.0" />

in the web.config, instead of version 2.0.0.0

And then closing and reopening visual studio with the same solution.

Tony
  • 200
  • 2
  • 5
1

I know that this topic is out of date, but I've just overcome the same problem and my resolution is not related to any one of the listed here.

The issue is that in my project properties the parameter "Output path" (Build->Output) was a folder different from just "bin\". After changing it to bin\, reopening the Studio and rebuilding my project, everything worked out!

Hopefully, it might help someone.

Oleg Safarov
  • 2,325
  • 14
  • 19
  • 1
    YES! many hours of debugging before I found this. Ever found a way to tell intellisense to look in another directory? (I've opened a question [here](https://stackoverflow.com/q/67405205)). – JHBonarius May 05 '21 at 16:39
  • I'm glad that my advice helped you. Unfortunately, I no longer have an access to that project from my answer, and for some reason I haven't yet managed to reproduce the issue in VS 2019 and a web project targeted to .NET 4.5. – Oleg Safarov May 10 '21 at 16:32
0

I am using VS 2015 professional. Faced the same issue, tried all mentioned above solutions and nothing worked. Neither "devenv.exe /ResetUserData" nor "deleting content of ComponentModelCache".

The only way I managed to solve the issue is by modifying the installation: Go to Program and Features -> Find Microsoft Visual Studio ... 2015 -> Click Change -> Select Modify -> Check "Microsoft Web Developer Tools" -> Click Update

That worked for me.

Alex P
  • 39
  • 5
0

i have read a lot of solutions, a i have lose much time, and when i was sure to not resolve the problem of visual studio 2015 intellisense, eureka, some one was giving the right solution: lean & clear 2 lines of code those I run in cmd (like administrator):

  1. C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE>devenv /updateco nfiguration
  2. C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE>devenv /clearcac he

whe restart visual studio maybe it ask to reinstall one tools that was broked. Well you do but still fron now your intellisense is going work agane. good luck at all and much thanks at Nadir

-1

Just do one thing and go to:

Tools > Extension & Update > Update Your Visual Studio Version

It take some time but after that working fine.

help-info.de
  • 6,695
  • 16
  • 39
  • 41
vishal joshi
  • 77
  • 1
  • 2
-2

Just Put a Break point on the First line

of Page. and remove it after few seconds... it will definitely work...