Sunday, February 19, 2012

Web Pages exception in ASP.NET MVC 3 application after installing MVC 4 Beta

After installing ASP.NET MVC 4 Beta I tried to run one of my MVC 3 applications and got this error:
System.InvalidCastException: [A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to [B]System.Web.WebPages.Razor.Configuration.HostSection. Type A originates from 'System.Web.WebPages.Razor, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_1.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'. Type B originates from 'System.Web.WebPages.Razor, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'.
For some reason the framework was loading version 2.0 of System.Web.WebPages.Razor.dll instead of version 1.0. To fix it I just set webpages:Version to 1.0 in Web.config:
   <add key="webpages:Version" value="1.0"/>

Saturday, February 18, 2012

ASP.NET MVC 4 Beta: Web API is not MVC

The ASP.NET MVC 4 Beta release includes a new API called ASP.NET Web API:
ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices. ASP.NET Web API is an ideal platform for building RESTful applications on the .NET Framework.
You can find a better description in this post. In short, Web API is WCF Web API rewritten in an MVC-ish way. It takes a lot of ideas from MVC, like Controllers, Routes, Model Metatada, Model Binding, Model Validation, Value Providers, Filter Attributes, etc., and adds WCF Web API features, like OData and non-ASP.NET hosting.

The bad thing is that, even though Web API looks and feels like MVC, it's not MVC. All those great MVC features we all love, the Web API team decided to copy/re-implement, instead of building on top of MVC. Web API does not depend on MVC. It doesn't even depend on ASP.NET.

The best thing about MVC is it's extensibility. Now all those great MVC extensions will have to be recompiled/adapted for Web API. This is a terrible design choice, all they had to do was provide more RESTful features directly in MVC, instead of creating the Web API beast.

Tuesday, February 14, 2012


There aren't many plugin solutions available for ASP.NET MVC, if you google mvc plugins you'll find many proof-of-concept on how to load views embedded as assembly resources, but few established projects. Loading embedded views is only one part of the puzzle, first we should focus on routing.

Sunday, February 12, 2012

Hello World 2.0

This is my second blog attempt. After falling in love with StackOverflow I decided I didn't need my (first) blog anymore, SO provided a much richer interaction. When I had a question I would just ask it on SO. If I had an answer, I would look for the question, if found and no answer looked like mine I would post my answer. A couple of times I post a question just to post my own answer, but that didn't feel right. With time SO got stricter on what kind of questions were allowed. Then came Programmers, but never really connected with it. I don't understand why that site, created for programming questions not suitable for SO, has so many closed questions. What's next? Programmers 2? I missed the freedom to just post anything I wanted, no rules, no scores, so here I am again. This time I'm much more skilled and experienced, so I hope to connect with a larger audience.