Encountered an unexpected error when attempting to resolve tag helper directive '@addTagHelper'

三世轮回 提交于 2019-12-03 03:25:44

问题


I'm using Visual Studio 2015 Community edition, and I've created an ASP.NET MVC 5 project.

When I open a view (Index of Home or any other), it shows first three lines of the page underlined with red as a syntax issue. Here is the error:

Encountered an unexpected error when attempting to resolve tag helper directive '@addTagHelper' with value 'Microsoft.AspNet.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNet.Mvc.Razor'. Error: Object reference not set to an instance of an object

The screenshot:

When I build the project, it build successfully. When I run it, it shows a lot of errors, but it runs the application.

The type or namespace name 'Mvc' does not exist in the namespace 'Microsoft.AspNet' (are you missing an assembly reference?)

and

'_Page_views_home_index_cshtml.ExecuteAsync()': no suitable method found to override

How can I get rid of this?


回答1:


Here's how I fixed the issue:

First, reset the Visual Studio Component Cache by closing Visual Studio and deleting this folder:

C:\Users\[Username]\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache

And finally, check the web.config files and change:

<appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
    ...
</appSettings>

to

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



回答2:


I had the same problem, but the above didn't work. I also deleted all 4 files in the Component cache which didn't work. I noticed that the line below <appSettings> was set to false. I changed it to true and the red squigs were gone.

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




回答3:


In my case it was the reference to System.Web.Mvc had disappeared.

There was lots of errors in the cshtml files but it would compile and run. Then I found that I had an error in the xxxcontrollers.cs file trying inherit controllers.

Seems it could compile because the dll was in bin already but it was giving errors.

I did not relish having to rebuild this project. That would be days and days.



来源:https://stackoverflow.com/questions/34920895/encountered-an-unexpected-error-when-attempting-to-resolve-tag-helper-directive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!