I just converted my blog from a Visual Studio 2008 project to a Visual Studio 2010 project using Visual Studio 2010’s conversion wizard. When you do that for a ASP.NET MVC 1.0 project the wizard automatically converts it to a MVC 2 project and changes all references to MVC 1.0 to MVC 2 in web.config.
As I’m using EPiServer CMS which at this point doesn’t support MVC 2 I changed those references back to MVC 1.0 in web.config and thought everything would work as before. But then I ran into a problem where the model object in strongly typed views wasn’t of the correct type, resulting in exceptions like this:
CS1061: 'object' does not contain a definition for 'Title' and no extension method 'Title' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
It took me a while to figure out what was going on since the error message was describing a symptom and not the problem. Since I had been using the standard template for ASP.NET MVC projects when I first set up the project it contains a separate web.config in the Views folder that I have never even bothered to open. Of course the wizard had changed there references from MVC 1.0 to MVC 2 there as well.
After changing
<pages validateRequest="false" pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<controls>
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
to
<pages validateRequest="false" pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<controls>
<add assembly="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
Everything works fine again.
PS. For updates about new posts, sites I find useful and the occasional rant you can follow me on Twitter. You are also most welcome to subscribe to the RSS-feed.
This blog is built with EPiServer Community, EPiServer CMS, ASP.NET MVC and a bunch of other great products. The source code is available for download at the projects page, where you also can read more about this site and my other projects.
read more
Comments
Matthew Fenelon 1 years ago
Thank you so much for publishing this page, I have been struggling with this issue for the last day!
john.gates@cubic.com 1 years ago
Many thanks, you're article put me on the right course- We had a related issue where we had upgraded an MVC S#arp project from VS 2008 to VS 2010 where the outer web config was set to MVC 2 while the inner view config was still at MVC version 1. The solution for me was to correct the View config to MVC 2.
Stu 11 months ago
Great stuff, exactly what I was looking for, thanks.
Paul 8 months ago
Many thanks for posting the fix.
That additional web.config file was a bit sneaky!
Xp 8 months ago
This is awesome.
I havent done a conversion. and I dont have the second web.config in Views folder. But somehow in the actual web.config in root had all set to MVC version 1.0.0.0. So I changed to Version 2.0.0.0.
Yes! Now my strongly typed views work!
You saved my day.
Thank you so much and long live.
Shaun 4 months ago
Saved me a ton of time, thanks for this post!
deerchao 3 months ago
Saved my sleep. Thanks!