Solving the mysterious CS1061: 'object' does not contain a definition for... exception after upgrading to a new Visual Studio version.
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.