InvalidCastException is thrown after installing ASP.NET MVC 4 Beta

前端 未结 9 1624
小鲜肉
小鲜肉 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 09:45

    Also as last step clear your bin folder from the project where the error is coming from.

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

    If you are experiencing this issue and you have tried the solutions above and this not work, pls check the web.config in your Views folder. There may be some configurations their that is conflicting the Web.config file in your App root folder

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

    Some of your code is running on the current MVC bits, while others have been pushed out to the newer. Without understanding the code, I can't tell you what specific bit is causing the issue.

    Having said that, I would never set up a beta on a production development machine. It is too easy to create a VM these days and run the beta on an image. In Windows 7+, you can boot the image off the metal and not take the perf hit, if you need that (with dev tool betas, you oft do).

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

    For the sake of completeness...

    You can also just turn off webpages altogether if you aren't using them.

    <appSettings>
        <add key="webpages:Enabled" value="false" />
    </appSettings>
    

    (I'm still not entirely clear on the relationship between razor views and webpages, but it seems my MVC app with razor views still works with webpages disabled.)

    0 讨论(0)
  • 2020-12-25 09:51
    1. In Visual Studio, create a new "throwaway" ASP.NET MVC 4 Application in a separate folder somewhere.
    2. Replace the web.config file in your Views folder with the freshly created Views web.config file from the new throwaway application.

    You will notice:

    System.Web.WebPages.Razor changes from Version=1.0.0.0 to Version=2.0.0.0 System.Web.Mvc changes from Version=3.0.0.0 to Version=4.0.0.0

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

    I had the same problem, but when migrating ASP.NET MVC 3 to ASP.NET MVC 4. This way I got on this topic. I have found a solution to the problem, but its source is different, it is not from WebPages version.

    I have followed the official guide (so to say) Upgrading an ASP.NET MVC 3 Project to ASP.NET MVC 4.

    To resolve the problem, you have to add in Web.Config (probably around previously added ones):

    <runtime><!-- Should be there by default, near end -->
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><!-- Should be there by default -->
        <dependentAssembly>..</dependentAssembly><!-- Should be there by default -->
            ... some other dependecy redirects ...
    
        <dependentAssembly>
            <assemblyIdentity name="System.Web.WebPages.Razor"
                publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
        </dependentAssembly>
    
            ... some other dependency redirects ...
        </assemblyBinding>
    </runtime>
    

    Also in the notes is not mentioned to change the Reference of System.Web.Helpers from 1.0.0.0 to 2.0.0.0 (delete and add the new one).

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