55

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:

@addTagHelper error message

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

Index View with errors

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?

2
  • Having the exact same issue today. Upgraded the project to MVC 5 and C# 6 and now every view is hosed with this crap. Site still works and compiles fine, but it makes development very difficult.
    – Kcoder
    Jan 25, 2016 at 23:21
  • I'll also add I'm using VS 2015 Enterprise and have updated MS.CodeDom to 1.0.1 (latest) and MS.Net.Compilers to 1.1.1 (latest) as well.
    – Kcoder
    Jan 25, 2016 at 23:25

3 Answers 3

110

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>
1
  • Create a new MVC project and compare the two web.config files with the ones in your project. Pay special attention to the version numbers of System.Web.WebPages.Razor and System.Web.Mvc to make sure they're up to date as well.
    – Kcoder
    May 18, 2016 at 16:05
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" />

1
  • I've tried changing the value to true and this didn't work for me. Mar 14, 2017 at 15:17
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.