Going through presentation hell – make sure you check your existing apps when you ...

:

Last night, Philly Dot Net had its annual 15 minutes of fame meeting to celebrate the groups 9th anniversary. I was privileged to be one of the speakers. The event was a lot of fun.The format is simple – you get 15 minutes to present a topic. You need to be ready – and there is definitely no time for mistakes. That said, I went through what all speakers go through from time to time…presentation hell! I was giving a short presentation on ajax, json and jquery in the MVC environment. The last time I gave the talk was at the Pittsburgh Code Camp a few weeks ago. I have given this talk in one form or another, 7-8 times in the past. Since Pittsburgh, I went ahead and installed the ASP MVC 3.0 RC. As an aside, ASP MVC 3 and the Razor View Engine looks to be an awesome product! In any case, in my presentation code, somehow, the system.web.mvc’s specific version attribute was flipped to false. All of a sudden, when I rebuilt the app, MVC 3 became the referenced library. The app built fine. However, when I launched the app, I got the dreaded mustard and ketchup error page!!! The error read:

The view at '~/Views/Home/Index.aspx' must derive from ViewPage, ViewPage<TModel>, ViewUserControl, or ViewUserControl<TModel>.

The words OH CRAP went through my mind. Given that we only have 15 minutes to work with and not wanting to de-rail the entire meeting, I relinquished the podium. SharePoint pro and MVP Mike Mukalian was the next speaker and like a true pro, stepped in. In the mean time, while Mike was presenting, I was trying to figure out what was going on. I didn’t have connectivity. I had a back up of my project and managed to get that to run. After Mike’s presentation, I went back up, a bit shaken, but nevertheless, managed to present the benefits of jQuery and jQueryUI. Eventually, the same error popped up, but by then, I was done. Getting the error again really threw me for a loop.

So..what happened?

As mentioned previously, the specific version attribute on the system.web.mvc reference was set to false. During my demo, the app rebuilt. Therefore, when I attempted to fire things back up, I ended up having a mismatch between the index view and the ASP MVC version my app was using. Obviously, if I had cranked up my app before the meeting, I would have discovered the problem and would have fixed it. So with that, no matter how sure you are, make sure you give yourself time to make sure your stuff works. Its a rule I usually follow. I didn’t last night and it burned me! The other thing is when installing new versions of libraries, make sure your existing apps still work. For ASP MVC apps, you want to make sure your build is tied to a specific version. The great thing about .NET is that different versions of the same library can sit side by side. By default, the specific version attribute is set to true. Somehow, in my app, the attribute was set to false. In spite of that, the app built without errors. You might be thinking that hacking the .proj file – setting the mvcbuildviews property to true would do the trick…. NO IT DOESN’T!! If you apply system.web.mvc v 3 to a 2.0 project and have your build compile the views…the build will still succeed. With this revelation, I’ll be submitting this to the team. Going from v 1 to 2 wasn’t a problem. But with 3 and the advent of the new Razor View Engine, it now becomes a problem. With this, I’ll also be suggesting to the team that as a default, build views should be set to true. And – we should be able to toggle that setting from the project properties page.

By the way, to toggle the build views functionality, open your web project (.csproj file) file in notepad. Look for: <MvcBuildViews>false</MvcBuildViews>. Set this property to true. Again, it would not have helped in this case, but nevertheless, it does afford your build process to catch errors in your views that would otherwise not be caught until deployment or in your QA process.

Finally, thanks for the kind comments at the conclusion of my talk. Looking to make lemonade from lemons, I hope this post proves to be useful and hopefully, it will help you avoid problems like this.

< JVP >