Razor intellisense not working in VS 2015

2019-01-11 10:09发布

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?

14条回答
相关推荐>>
2楼-- · 2019-01-11 10:33

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.

查看更多
Root(大扎)
3楼-- · 2019-01-11 10:33

Just do one thing and go to:

Tools > Extension & Update > Update Your Visual Studio Version

It take some time but after that working fine.

查看更多
成全新的幸福
4楼-- · 2019-01-11 10:39

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.

查看更多
神经病院院长
5楼-- · 2019-01-11 10:43

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.

查看更多
beautiful°
6楼-- · 2019-01-11 10:44

Just Put a Break point on the First line

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

查看更多
男人必须洒脱
7楼-- · 2019-01-11 10:45

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

查看更多
登录 后发表回答