Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Nasty "Gotcha" with ASP.NET MVC and Views

We just spent far too long on what turned out to be a stupid problem ... we kept getting an error telling us that the view did not inherit from System.Web.UI.Page ... unfortunately the guy who was working on the particular view and controller could not think of a specific change he had made to cause this error, and looking at the code didn't reveal one either.

The problem was actually quite subtle, and quite stupid ...

A short while before the developer had decided to change the view from being an ".aspx" to being a ".ascx", so removed the view from the solution, added a new view that was a UserControl, and carried on working.  What he hadn't done was to actually delete the .aspx file, and even if he had done that, the other developers would have got this weird error too unless they pulled a clean copy of the solution, or manually deleted the files from their disk. (clarification: El Guapo pointed out I was being ambiguous here ... if the file is *deleted* from the *solution* then it will go from disk and from SCM, if if is removed from the solution and then deleted it will remain in other developer's directories *if* a VS addin like Ankh is being used, as the Update will operate against the solution and referenced files, not the folder structure)

When ASP.NET MVC is told to render a view, by using RenderPartial("MyView") or return ("MyView") for example, it goes off merrily and scans the file system for a file matching "MyView.ascx" or "MyView.aspx" (presuming the default ViewEngine) - however if the view exists on disk in both forms, it is a bit of luck as to which actually gets returned and is rendered. Removing the old file fromn the solution is not enough, it still exists on disk - delete the old one and all is well. Hopefully this is a fairly infrequent problem, but it was a real pain to figure out.

So if you get an odd problem in ASP.NET MVC relating to Views ... just make sure you haven't got old files in your directory structure!


Posted 09-04-2008 9:27 AM by Jak Charlton
Filed under: , ,

[Advertisement]

Comments

ASP.NET MVC Archived Blog Posts, Page 1 wrote ASP.NET MVC Archived Blog Posts, Page 1
on 09-04-2008 9:06 AM

Pingback from  ASP.NET MVC Archived Blog Posts, Page 1

Arjan`s World » LINKBLOG for September 4, 2008 wrote Arjan`s World » LINKBLOG for September 4, 2008
on 09-04-2008 2:54 PM

Pingback from  Arjan`s World    » LINKBLOG for September 4, 2008

El Guapo wrote re: Nasty "Gotcha" with ASP.NET MVC and Views
on 09-04-2008 3:59 PM

"even if he had done that, the other developers would have got this weird error too unless they pulled a clean copy of the solution, or manually deleted the files from their disk.'

WOAH... What ancient source control system are you using?

Jak Charlton wrote re: Nasty "Gotcha" with ASP.NET MVC and Views
on 09-04-2008 4:25 PM

SVN ... the one that doesn't delete files just because the reference in the project file was removed ...

El Guapo wrote re: Nasty "Gotcha" with ASP.NET MVC and Views
on 09-04-2008 8:33 PM

SVN does propagate deletions!

Jak Charlton wrote re: Nasty "Gotcha" with ASP.NET MVC and Views
on 09-05-2008 1:45 AM

El Guapo - I have updated the post to clarify my bad wording ... sry for the confusion ...

Reflective Perspective - Chris Alcock » The Morning Brew #173 wrote Reflective Perspective - Chris Alcock » The Morning Brew #173
on 09-05-2008 3:32 AM

Pingback from  Reflective Perspective - Chris Alcock  » The Morning Brew #173

Tommy wrote re: Nasty "Gotcha" with ASP.NET MVC and Views
on 09-05-2008 3:56 AM

I prefer VisualSVN over Ankh, but thats another discussion. ;-)

Jak Charlton wrote re: Nasty "Gotcha" with ASP.NET MVC and Views
on 09-05-2008 5:48 AM

VisualSVN rocks ... but Ankh is free ... I pick my battles carefully ... and on the "go spend lots of money" front I wanted to get ReSharper for everyone :D

The Visual SVN argument would go:

me: "I have decided we should use SVN for our source control because VSS is not very good"

client: "OK, how much?"

me: "totally free"

client: "No brainer,  go ahead"

me: "oh, SVN server is free, but the VS plugin costs $100 a developer"

client: "Woah donkey!!!  So what exactly is so wrong with VSS"

And then we spend days or weeks going back and forth justifying why the SCM solution from the world's largest sofware company is not good, and SVN is better ...  and then we are in friction land ...

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)