c# - 类型 'System.Web.Mvc.MvcWebRazorHostFactory' 的表达式不能用于返回类型 'System.Web.WebPages.Razor.WebRazorHostFactory'

标签 c# asp.net asp.net-mvc asp.net-mvc-4 razor

我有一个用 MVC 3 开发的网站,尝试使用 Visual Studio 2012 打开,它更新项目并尝试运行该项目,但出现错误:

The expression of type 'System.Web.Mvc.MvcWebRazorHostFactory' can not be used for return type 'System.Web.WebPages.Razor.WebRazorHostFactory'

System.Web.Mvc 将 DLL 更新到版本 4.0.0.1。

Web.config

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=152368
  -->
<configuration>
    <connectionStrings>
        <add name="Main" connectionString="Data Source=sacteste;Persist Security Info=True;User ID=automa;Password=auto2020;Unicode=True"
            providerName="System.Data.OracleClient"/>
  </connectionStrings>
    <appSettings>
        <add key="webpages:Version" value="1.0.0.0"/>
        <add key="ClientValidationEnabled" value="true"/>
        <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
        <add key="AssuntoEmailNotas" value="Nota fiscal emitida"/>
        <add key="TemplateEmailNotas" value="C:\DotNet\PIF\GestaoNFSe\templateNFSe.cshtml"/>
        <add key="TemplateEmailCobranca" value="C:\DotNet\PIF\GestaoNFSe\templateCartaCobranca.cshtml"/>
        <add key="EmailFromEndereco" value="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4e2a2b3d2b203821223827232b203a210e232b292f3d3b22602d2123602c3c" rel="noreferrer noopener nofollow">[email protected]</a>"/>
        <add key="EmailFromNome" value="Megasul"/>
        <add key="ChaveCriptografia" value="_nfse_megasul#1234"/>
        <!-- alterar a chave invalida todos os e-mails já enviados! -->
        <add key="DiretorioLicencasCobreBem" value="C:\CobreBemX\"/>
        <add key="enableSimpleMembership" value="false"/>
        <add key="autoFormsAuthentication" value="false"/>
    </appSettings>
  <system.web>
        <compilation debug="true" targetFramework="4.0">
            <assemblies>
                <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            </assemblies>
        </compilation>
        <authentication mode="Forms">
            <forms loginUrl="~/Account/LogOn" timeout="2880"/>
        </authentication>
        <membership defaultProvider="MegaMembershipProvider">
            <providers>
                <clear/>
                <add name="MegaMembershipProvider" applicationName="WebRAT" type="MegaControls.Membership.MegaMembershipProvider" connectionStringName="Main"
                    enablePasswordRetrieval="true" enablePasswordReset="true" requiresQuestionAndAnswer="false" minRequiredNonAlphanumericCharacters="0"
                    maxInvalidPasswordAttempts="10" minRequiredPasswordLength="1" writeExceptionsToEventLog="false" passwordFormat="Clear"/>
                <!--119746-->
            </providers>
        </membership>
        <profile>
            <providers>
                <clear/>
                <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
            </providers>
        </profile>
        <roleManager enabled="false">
            <providers>
                <clear/>
                <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/"/>
                <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/"/>
            </providers>
        </roleManager>
        <pages>
            <namespaces>
                <add namespace="System.Web.Helpers"/>
                <add namespace="System.Web.Mvc"/>
                <add namespace="System.Web.Mvc.Ajax"/>
                <add namespace="System.Web.Mvc.Html"/>
                <add namespace="System.Web.Routing"/>
                <add namespace="System.Web.WebPages"/>
            </namespaces>
        </pages>
        <customErrors mode="Off"/>
    </system.web>
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
        <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>
    <system.net>
        <mailSettings>
            <smtp deliveryMethod="Network">
                <network host="192.168.0.201" defaultCredentials="false" userName="jani" password="jani"></network>
            </smtp>
        </mailSettings>
    </system.net>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
                <bindingRedirect oldVersion="1.0.0.0-3.0.0.1" newVersion="4.0.0.1"/>
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

最佳答案

自 2015 年 10 月 26 日起,打开位于 Views 文件夹中的 Web.config 文件并将 Factorytype 版本更改为 5.0.0.0。

来自

<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

关于c# - 类型 'System.Web.Mvc.MvcWebRazorHostFactory' 的表达式不能用于返回类型 'System.Web.WebPages.Razor.WebRazorHostFactory',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26546943/

相关文章:

c# - ASP.NET MVC 使用强类型 ViewModel 将数据从 View 保留到 Controller

c# - 将关系数据库数据表示为 XML 并使用 XPath 获取结果

c# - 如何在 C# 中从 BindingSource 获取值

c# - 散列对象集 C#

c# - 运行由 ASP.NET 网页请求触发的异步操作

asp.net - 跨回发保留复选框状态

c# - 如何确保 WCF 服务不会与数据库并行通信

asp.net - 启用 NET 的开始标记需要 SHORTTAG YES

asp.net - 在 Visual Studio 2015 中保存 *.cs 或 *.cshtml 文件后 IIS Express 停止

c# - "Failed to initialize database."