Devlico.Us
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @devlicious

Casey Charlton - Insane World

Hang the code, and hang the rules. They're more like guidelines anyway


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!



Comments

ASP.NET MVC Archived Blog Posts, Page 1 said:

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

# September 4, 2008 9:06 AM

Arjan`s World » LINKBLOG for September 4, 2008 said:

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

# September 4, 2008 2:54 PM

El Guapo said:

"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?

# September 4, 2008 3:59 PM

Casey Charlton said:

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

# September 4, 2008 4:25 PM

El Guapo said:

SVN does propagate deletions!

# September 4, 2008 8:33 PM

Casey Charlton said:

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

# September 5, 2008 1:45 AM

Reflective Perspective - Chris Alcock » The Morning Brew #173 said:

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

# September 5, 2008 3:32 AM

Tommy said:

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

# September 5, 2008 3:56 AM

Casey Charlton said:

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 ...

# September 5, 2008 5:48 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Casey Charlton

A somewhat passionate and opinionated developer, with occassional sparks of wisdom, and occasional useful information. Check out Devlicio.us!

Our Sponsors

Proudly Partnered With