InvalidCastException is thrown after installing ASP.NET MVC 4 Beta

前端 未结 9 1625
小鲜肉
小鲜肉 2020-12-25 09:29

I get the following exception after installing ASP.NET MVC 4 Beta on a machine with ASP.NET MVC 3.

System.InvalidCastException was unhandled by user c

相关标签:
9条回答
  • 2020-12-25 10:00

    I found another way of getting this to work, along the line to a Taiwanese's blog on upgrade from MVC 2 to MVC 3: http://blog.kkbruce.net/2011_04_01_archive.html (You can actually use Microsoft Translate in IE10 to see the English version and it is a fairly good translation...)

    The trick is to find all the versions that relate to MVC3 (such as Razor, Mvc, Helper assemblies, you will know what they are if you go to your references and check out all the newer versions of your referenced assembly) and change them from 1.0.0.0 to 2.0.0.0 and from 3.0.0.0 to 4.0.0.0 (since the public keys are the same). You can also try removing the versions as per the blog.

    Another important thing is that these settings are in all the Web.Configs. So not only under you root, but also under View, Area/{Area}/View, etc.

    I feel this solution can let you upgrade to the MVC4 completely instead of having a hybrid, which didn't work for me anyways.

    0 讨论(0)
  • 2020-12-25 10:03

    One more, rather late, solution ... I ran into this same problem. Did all the fixes listed here (Thank You All!!!) but could not get past the error. Finally, in desperation, I found a web.config file in the Views directory. In this file, I found several references to the version of System.Web.Mvc and bumped all of them up to "4.0.0.0". More importantly, I found the following lines and updated the version numbers for "system.web.webPages.Razor" from "1.0.0.0" to "2.0.0.0" and suddenly, everything was working once again. Hopefully, this will help someone else.

    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
    

    Steve G.

    0 讨论(0)
  • 2020-12-25 10:09

    Try adding the following in your web.config:

    <appSettings>
      <add key="webpages:Version" value="1.0.0.0"/>
    </appSettings>
    

    The issue might be due to multiple build providers being registered and the latest winning.

    0 讨论(0)
提交回复
热议问题