50

So this has been bugging me for a while, but sometimes in my Visual Studio 2013 ASP.NET MVC4 project, I will delete an unused ViewModel class, and will get an error on the next compile that looks like this (for a ViewModel called "MostRecentMemberListing.cs" that I just deleted):

Error 9 The type or namespace name 'MostRecentMemberListing' does not exist in the namespace 'MembershipCenter.ViewModels' (are you missing an assembly reference?) c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\temp\3e932790\42b7ff67\App_Web_cvlbfbci.1.cs 29 MembershipCenter

If I double-click the error in the "Error List" panel of VS, it opens a file located in this path: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\temp\3e932790\42b7ff67, which is a system-generated view file(?) with a classname of _Page_Views_Home_MostRecentMember_cshtml.

I've tried deleting the weird file itself, as well as its containing folder, and ITS containing folder, all the way up the path to the temp folder under Temporary ASP.NET Files. But everytime I re-compile my project all those folders and files are re-created in that directly and I get the same compile error.

I am building my Views during the compilation, via <MvcBuildViews>true</MvcBuildViews> in the project file. If I turn this setting off, I can build + run just fine, but when I turn it back to true, the build error returns.

Has anyone encountered this error before? Is it related to IIS? I am running Local IIS, not IIS Express.

Graham
  • 3,217
  • 1
  • 27
  • 29

8 Answers8

65

This is not related to IIS, local or otherwise. That long, strange file name you are seeing is the name the compiler gives to a view when it compiles it. What everything you have described is telling you is that you have a compilation error in one of your views. It could be mismatched HTML tags, a bad model property call, etc.

Looking at your error message, you have a view in the /Views/Home/MostRecentMember.cshtml. Further, it appears that you are indeed either missing the namespace for your model declaration or declared the wrong namespace for the model that you are trying to send in.

Deleting the strangely named file will do nothing as when you rebuild, it will come back, most likely with a different name.

Tommy
  • 39,592
  • 10
  • 90
  • 121
  • 4
    You are exactly correct! I forgot that I had a View (`/Views/Home/MostRecentMember.cshtml`) that used the newly-deleted class as its model. When I deleted the View that was referencing the non-existent model, the compiler error went away. Thanks. – Graham Jan 29 '14 at 13:19
  • 12
    A bad reference to an assembly in the `` section of either web.config can also cause this behavior. – Tieson T. Oct 16 '14 at 23:24
  • @TiesonT.: thank you for mentioning "EITHER" web.config... I hadn't noticed that the developers had scattered multiple web.configs around the place, each of which needed their modified! – ALEXintlsos Nov 05 '14 at 22:41
  • 7
    It was trying to compile views that were no longer included in the project :( So much grief. – Shelby115 Jan 07 '15 at 14:44
  • 1
    In VS2015 there is some kind of bug where it has held onto my views which were in the Account folder (which I have now deleted (including from by file explorer, not just in VS)) and it is causing an eternal bug for me. I have no choice but to just disable compiling views for now – Worthy7 Aug 24 '16 at 00:15
  • 1
    @Worthy7 - did you do a solution clean and rebuild? Also, you can manually delete all sub folders and elements from the obj folder of your web application (unless you have been dropping things in there?). This is the trick I have to use when I get the "multiple web.configs have been defined" error. I assume it may work the same for you here? – Tommy Aug 24 '16 at 12:43
  • 1
    Honestly I don't know how, but I fixed it. – Worthy7 Aug 24 '16 at 13:40
  • In Visual Studio 2015 I had to delete obj and bin folders in order to fix this after I renamed view models. – Leonid Vasilev Mar 24 '17 at 13:57
14

I had this again today, there must be a bug in visual studio that causes it to try and compile all cshtml files in the views folder. Even if they are not part of the project. Your best bet is to click show all files in the solution explorer, find the rogue file and delete it.

dibs487
  • 1,294
  • 4
  • 21
  • 36
4

I faced the same error after I changed the namespace of web application, I also renamed my solution and web project also. After lots of tricks and tips finally this solution worked for me.

  1. I inspected the app App_start files to find any reference to old namespace and found nothing
  2. I then searched web.config and Global.asax but no success.
  3. Finally I searched in web.config listed under Views folder in solution and there I found reference of old name space under. Changed this to NewNamespace and ran the application. This time it worked.

vaibhav
  • 41
  • 3
1

For others. It can also be forgetting the equals sign
<%ThankyouMessage%> instead of
<%=ThankyouMessage%>

Ref <%$, <%@, <%=, <%# ... what's the deal?

Community
  • 1
  • 1
hogarth45
  • 3,387
  • 1
  • 22
  • 27
1

This error means that your view is using a model that cannot be found. This usually happens when you refactor/ remove model without updating views!

Fixing the reference to model in the affected view should solve this problem.

Else, try cleaning up ASP.Net temp directory: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files

Nitin A.
  • 41
  • 2
1

I have the same issuse and found the problem is the namespace of C# sensitive. Namespace in file .cshtml of view is upper "@model IEnumerable" and namespace space of class is Camel format "Abc.Def.Class".

I change the namespace in .cshtml to Camel format and it run.

N T
  • 21
  • 2
1

enter image description here

I had this silly problem, if you notice the QuestionAnswer folder is an icon of a folder thats not included in the project and a file inside it references model that is non-existing or in the same state as the file, Excluded from project.

I had to select my project and show all files on solution explorer like image below enter image description here

I then deleted the folder, file and the model that was also excluded from project causing build error. I hope the pictures help and happy coding.

wilaponce
  • 101
  • 5
1

If another one is facing this issue, be sure that you don't have a namespace specified in web.config file

enter image description here

Those namespaces are added automatically to view when compiling and if the namespace doesn't exists it will throw an error.

It frequently happens when you rename a namespace.

JohnB
  • 18,046
  • 16
  • 98
  • 110
José Polanco
  • 574
  • 4
  • 19