14

I have an issue which seems to have been reported here:

Need razor view engine auto-complete to work in a class library?

My issue is the following Warning:

G:\Accountable\Accountable\Views\LedgerUser\EditorTemplates\LedgerServiceViewModel.cshtml: ASP.NET runtime error: There is no build provider registered for the extension '.cshtml'. You can register one in the section in machine.config or web.config. Make sure is has a BuildProviderAppliesToAttribute attribute which includes the value 'Web' or 'All'.

This issue is apparent in all my views. Sample images below.

enter image description here

enter image description here

enter image description here

Now all posts and references online that I have found are referencing to adding various Web.config (as mentioned in the previous post) options, but this doesn't seem to work, as I have these configurations defaulted in the project. Here are my Web Configs:

Main Web.config

View root Web Config

I think this issue maybe while im also getting the following compiler errors on the Views:

The name 'Html' does not exist in the current context

enter image description here

What am I doing wrong?

Community
  • 1
  • 1
garfbradaz
  • 3,424
  • 7
  • 43
  • 70
  • Almost duplicate of this one: http://stackoverflow.com/questions/4158573/need-razor-view-engine-auto-complete-to-work-in-a-class-library – David Mårtensson Oct 07 '12 at 15:35
  • Hey David. Thanks for the comment. Yes i referenced that in the post above. I cannot see any difference with the default ones created in the Project. – garfbradaz Oct 07 '12 at 15:37

5 Answers5

22

Arrrgghhh i had missed the following from the ROOT Web.config:

 <compilation debug="true" targetFramework="4.0">
  <!-- New -->
  <assemblies>
    <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  </assemblies>
</compilation>

This allowed fixed the error and allowed me to use Intellisense within the View.

garfbradaz
  • 3,424
  • 7
  • 43
  • 70
  • 1
    I don't really know why this fixed it, but it did. It was working fine and then I reversed a very small hunk on a file in git and my whole project blew up. This seemed to fix it. – Jesse Seger Jul 12 '13 at 19:46
  • 1
    This worked for mvc5, just change the version to `3.0.0.0` and the public key to the one in your web.config (it's at the end of the file). – Vahid Amiri Jan 09 '16 at 20:54
  • in MVC 5 updated all versions and keys but the error is still here. – Sonic Soul Oct 04 '16 at 19:00
3

Putting back the following lines in root Web.config fixed:

<system.web>
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
</system.web>
abatishchev
  • 98,240
  • 88
  • 296
  • 433
2

I got it working by simply unloading and reloading the project. All the namespaces above were already there in the root web.config and I was still getting this issue.

Mukus
  • 4,870
  • 2
  • 43
  • 56
2

Removing the temporary asp.net framework files works for me.

Stop IIS and remove everything under this folder:

C:\Windows\Microsoft.NET\Framework64\[framework version]\Temporary ASP.NET Files

Then restart IIS. Bam!

Fernando Neira
  • 3,944
  • 2
  • 24
  • 23
  • 1
    Starting receiving this error for no apparent reason - my project was working for years previously. This worked for me, thanks! – Jesse MacVicar May 26 '16 at 17:07
0

I tried by restart IIS, removed Temporary ASP.NET Files and changing the compilation tag in the web config file. None of them work for me.

I fixed the issue by removing and adding System.Web.MVC to the project.

In my case Razor syntax are Highlighted in red.

Kapila Perera
  • 837
  • 1
  • 11
  • 24