简体   繁体   English

Visual Studio 2015 Broken Razor Intellisense

[英]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.安装并修复我的VS2015实例后,我仍然无法让智能感知(服务器端)在我的 MVC 视图中工作。 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.当我在会话中第一次打开.cshtml文件并被寻址到 Activitylog 文件时,我会收到消息提示的警报。 Error message retrieved in ActivityLog.xml (short version):在 ActivityLog.xml(简短版本)中检索到的错误消息:

System.ArgumentException: Item has already been added. System.ArgumentException:已添加项目。 Key in dictionary: 'RazorSupportedRuntimeVersion'键入字典:'RazorSupportedRuntimeVersion'

Here's the full version:这是完整版:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. System.Reflection.TargetInvocationException:调用的目标已抛出异常。 ---> System.ArgumentException: Item has already been added. ---> System.ArgumentException:已添加项目。 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.RuntimeCo字典中的:'RazorSupportedRuntimeVersion'正在添加键:System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add) at System.Collections.Hashtable.Add(Object key, Object value) 中的'RazorSupportedRuntimeVersion'。 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) 在 Microsoft.Html.Editor.ContainedLanguage.Razor.RazorUtility.TryGetRazorVersion(ITextBuffer textBuffer, Version& razorVersion) 在 Microsoft.Html.Editor.ContainedLanguage. ITextBuffer textBuffer) --- 内部异常堆栈跟踪结束 --- 在 System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeCo nstructorInfo.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) nstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 在 System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfoculture, Object[] activationAttributes, StackCrawlMark& stackMark) 在 System. Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfoculture, Object[] activationAttributes) at System.Activator.CreateInstance(Type type, Object[] args) at Microsoft.Html.Editor.ContainedLanguage。 Common.ContainedCodeErrorTaggerProvider'1.CreateTagger[T](ITextBuffer textBuffer) 在 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.如果有任何帮助,我有一些字体着色自定义,并安装了 Web Essentials、Bundler & Minifier 和 Web Compiler 扩展。

UPDATE : it happens either when I open an existing web application or when I create a brand new one from scratch.更新:当我打开现有的 Web 应用程序或从头开始创建一个全新的 Web 应用程序时,就会发生这种情况。 There's also an instance of VS2013 installed and running on the same machine.还有一个VS2013的实例安装并运行在同一台机器上。

完全没有智能

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.提前致谢。

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:在我的情况下,删除此目录的内容允许 IDE 恢复:

%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)编辑:我刚刚遇到了这个可能也很方便的 - 清除 MEF 组件缓存(打开 VSIX 库)

I solved this problem by resetting the user data我通过重置用户数据解决了这个问题

devenv.exe /resetuserdata

and remove the ".vs" folder in my project.并删除我的项目中的“.vs”文件夹。


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.您将丢失任何自定义键盘快捷键、已安装的扩展程序等。

FWIW, I had this problem with VS 2015 Enterprise on two different machines. FWIW,我在两台不同的机器上使用 VS 2015 Enterprise 遇到了这个问题。 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.在另一台机器上,我不得不完全卸载并重新安装 VS,问题消失了一段时间。 On both machines, the problem came back after I installed an extension (once when installing Web Essentials, once when installing Git Diff Margin).在两台机器上,安装扩展后问题又回来了(安装 Web Essentials 时一次,安装 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.我烧毁了一个 MSDN 技术支持案例,答案是......是的,这是一个错误,MS 知道它,他们正在处理它。

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.最近,我安装了 NuGet 包管理器的更新,当 VS 重新启动时,它开始出现这个问题。 I ran devenv.exe /resetuserdata , but that didn't help;我运行了devenv.exe /resetuserdata ,但这没有帮助; it was still broken.它还是坏了。 So I tried again (ran devenv.exe /resetuserdata ) and, bada bing bada boom, the problem went away (for now).所以我再次尝试(运行devenv.exe /resetuserdata ),并且,bada bing bada 繁荣,问题消失了( devenv.exe /resetuserdata )。 The moral seems to be something along the lines of "if at first you don't succeed..."道德似乎是“如果一开始你没有成功......”

Might have happened due to having ReSharper.可能是因为使用了 ReSharper。

It will be fixed in future versions, but as of now (version 10.0.2), it is broken.它将在未来版本中修复,但截至目前(版本 10.0.2),它已损坏。 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. ReSharper 会覆盖 Visual Studio 的 IntelliSense,因此它不会工作,这也解释了为什么运行devenv.exe /ResetUserData修复它,因为它删除了 ReSharper。

Manually return the IntelliSense power to VS through the menu:通过菜单手动将 IntelliSense 电源返回给 VS:
ReSharper >> Enviroment >> IntelliSense >> Fill the following: ReSharper >> Enviroment >> IntelliSense >> 填写以下内容:
在此处输入图片说明

And this is how the IntelliSense from VS should look:这就是来自 VS 的 IntelliSense 的外观:
在此处输入图片说明

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. Visual Studio 的更新(我怀疑 2015 年 9 月的 TypeScript 更新)卸载了 Visual Studio 2015 的 Web 开发人员工具组件。这导致 IntelliSense 无法工作。

I installed Web Developer Tools in the installer options again AND deleted ComponentModelCache after the installation.我再次在安装程序选项中安装了 Web Developer Tools,并在安装后删除了 ComponentModelCache。 That worked for me.那对我有用。

This fixed it for me right away.这立即为我修复了它。

In Visual Studio:在 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单击工具->选项->文本编辑器->所有语言->常规取消选中“自动列表成员”取消选中“参数信息”选中“自动列表成员”(是的,您刚刚取消选中的那个)选中“参数信息”(再次,您刚刚取消选中的那个)单击确定

To add my 2 cents.添加我的 2 美分。 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 http://www.c-sharpcorner.com/blogs/how-to-resolve-intellisense-issue-in-visual-studio1

In particular this one特别是这个

Solution 4:解决方案4:

Next, reset the Settings from the following location.接下来,从以下位置重置设置。

Tools->Import and Export settings->Reset all settings.工具->导入和导出设置->重置所有设置。

From there I choose Visual C#从那里我选择Visual C#

The /ResetUserData solution is your best bet, but I also think I have found out a possible cause of this... /ResetUserData解决方案是你最好的选择,但我也想我已经找到了这个的可能原因......

I am currently using Umbraco to create Macro Partials in the BackOffice.我目前正在使用 Umbraco 在后台创建宏部分。 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.创建这些文件后,我单击“隐藏/显示所有文件”按钮以在我的解决方案中显示宏部分,而 Razor 语法突出显示似乎停止工作,因此我猜测是在您的解决方案中引入了不是直接通过 VS 创建的新文件导致这个问题。

Even when adding the files to the solution the Syntax Highlighting doesn't work.即使将文件添加到解决方案中,语法突出显示也不起作用。

Sometimes, the VS IDE does not show IntelliSense at all.有时,VS IDE 根本不显示 IntelliSense。

I just close the solution, close VS, then reopen it, and the problem is solved.我只要关闭解决方案,关闭VS,再重新打开,问题就解决了。

There is another solution, without reset all user data还有另一种解决方案,无需重置所有用户数据

(but only window layouts/toolbars): (但只有窗口布局/工具栏):

close all VS2015 instances, [eventually backup, and] delete the folder:关闭所有 VS2015 实例, [最终备份,并]删除文件夹:

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

Now, re-open VS2015: layout was reset to factory preset, but Razor syntax would work现在,重新打开 VS2015:布局已重置为出厂预设,但 Razor 语法可以使用

FYI: My VS 2015 PRO installation has full install with all 3-rd parties.仅供参考:我的 VS 2015 PRO 安装已与所有 3 方完全安装。

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. Craig Goldensoph 所写的内容在一定程度上帮助我找到了解决方案。

So first I did: Uncheck all checkboxes for Text Editor-> All Languages->General Statement completion:所以首先我做了:取消选中文本编辑器->所有语言->一般语句完成的所有复选框: 在此处输入图片说明

After Click OK- Reopen Option Dialog again: And check all for the same section:单击确定后 - 再次重新打开选项对话框:并检查所有相同部分: 在此处输入图片说明

and apply settings again.并再次应用设置。 You have to Restart your Visual studio.您必须重新启动 Visual Studio。 After restart it will take a time to load , but after that it worked for me.重新启动后,加载需要一些时间,但之后它对我有用。

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.运算符,按“Ctrl + Space”键,这将强制出现 IntelliSense 对话框。

I was having this issue when working with .cshtml MVC razor files.我在使用 .cshtml MVC razor 文件时遇到了这个问题。

Mine was a slight pain in the keester but seemed to work.我的 keester 有点痛,但似乎有效。 In my case it was a .aspx File that wouldn't do intellisense anymore (after I stupidly changed the .aspx filename...lesson learned!)就我而言,它是一个 .aspx 文件,它不再执行智能感知(在我愚蠢地更改了 .aspx 文件名之后......吸取了教训!)

  1. I copied all my code out of the files (.aspx & .cs) into notepad for example.例如,我将文件(.aspx 和 .cs)中的所有代码复制到记事本中。
  2. Deleted the .aspx file (which in turn deleted all child files).删除了 .aspx 文件(进而删除了所有子文件)。
  3. Saved my project.保存了我的项目。 Created a new .aspx file with the same name.创建了一个具有相同名称的新 .aspx 文件。
  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!希望 MS 能在这些年中解决这个问题!

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.将断点放在任何一行上,然后等待 5 秒钟,其中不起作用,然后转到第一行并将断点放在那里,当您设置断点时,它会要求设置断点。 在此处输入图片说明 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.我有 VS 2015 社区版。以前有 VS 2015 企业版,它发生在那里,但在获得社区后,我发现同样的情况发生并且相同的解决方案适用于两者。

I found that solution by accidently during work.Also do that when project is not running.and you can remove that break point also.我在工作期间偶然发现了该解决方案。在项目未运行时也这样做。您也可以删除该断点。

您不需要重置所有内容,只需从%LocalAppData%\\Microsoft\\VisualStudio\\14.0\\ComponentModelCache删除所有文件并重新启动 VS,就可以了。

I've posted this answer on another SO question, just because I want to prevent people wasting the time I've just wasted.我已经在另一个 SO 问题上发布了这个答案,只是因为我想防止人们浪费我刚刚浪费的时间。 My problem was that I'd added files to a project, but not included them.我的问题是我已将文件添加到项目中,但未包含它们。 So I chosen to show all files:所以我选择显示所有文件:

在此处输入图片说明

then chose to include folders:然后选择包含文件夹:

在此处输入图片说明

The problem only shows up when you open an MVC website as a project, and not when you open it as a website directly.该问题仅在您将 MVC 网站作为项目打开时才会出现,而当您将其直接作为网站打开时不会出现问题。

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 Razor 智能感知在 VS 2015 中不起作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Visual Studio 2015 不是语法高亮剃刀,也不是 Intellisense - Visual Studio 2015 not syntax highlighting razor nor Intellisense Visual Studio 2015智能感知 - visual studio 2015 intellisense Visual Studio、Razor、BuildProviders 和 Intellisense - Visual Studio, Razor, BuildProviders and Intellisense Visual Studio 2015 智能感知与 css 字体真棒 - Visual studio 2015 intellisense with css font awesome 在调试过程中未出现Visual Studio 2015智能感知 - Visual Studio 2015 intellisense not appearing during debug Visual Studio 2015 Intellisense中没有Bower包 - Visual Studio 2015 No Bower Packages In Intellisense MVC 4 IntelliSense在Visual Studio 2010中无法在Razor中运行 - MVC 4 IntelliSense is not working in Razor in Visual Studio 2010 在cshtml编辑器中触发IntelliSense时Visual Studio 2015(更新1)崩溃 - Visual Studio 2015 (Update 1) crashes when triggering IntelliSense in cshtml editor 在Visual Studio 2015中滚动智能感知列表的键绑定是什么? - What are the key bindings for scrolling through an intellisense list in Visual Studio 2015? Intellisense不适用于使用Xamarin的Visual Studio 2015中的.cs文件 - Intellisense not working for .cs files in Visual Studio 2015 with Xamarin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM