从.NET 3.5更改为4.5.1会导致app无法运行

时间:2017-07-31 17:25:37

标签: asp.net .net

我有一个最初在.NET 3.5上运行的.NET Web应用程序,但是将其升级到.NET 4.5.1。当我尝试运行该应用程序时,出现以下错误:

Configuration Error

Description: An error occurred during the processing of a configuration file 
required to service this request. Please review the specific error details 
below and modify your configuration file appropriately. 

Parser Error Message: Unrecognized attribute 'targetFramework'. Note that 
attribute names are case-sensitive.

Source Error: 


Line 63:        debugging ASP.NET files.
Line 64:        -->
Line 65:        <compilation defaultLanguage="c#" debug="true" targetFramework="4.5.1" />
Line 66:        <!--  CUSTOM ERROR MESSAGES
Line 67:        Set customErrors mode="On" or "RemoteOnly" to enable custom error messages, "Off" to disable. 

Version Information: Microsoft .NET Framework Version:2.0.50727.8745; ASP.NET Version:2.0.50727.8745

正如您在最后一行所看到的,此应用程序仍在使用.NET Framework verison 2.0.50727.8745。

我让我的同事在从源代码控制中获取并运行它之后打开解决方案并使用.NET 4.0。*并且他没有看到此错误。这让我相信我的机器有问题。我查看了applicationhost.config,我甚至没有看到我的应用程序列出,更不用说它正在使用哪个.NET版本了。为什么它会在他的机器上运行而不是我的?我有一个我需要实现的错误修复,如果我不能运行不会发生的应用程序。

2 个答案:

答案 0 :(得分:2)

将您的应用池更改为使用v4.0运行时。它失败的机器完全有可能甚至没有安装v4.0运行时。

答案 1 :(得分:0)

这是因为位于applicationhost.config目录中的IIS Express配置.vs。它包含对项目的应用程序池分配:

<system.applicationHost>

    <applicationPools>
        <add name="Clr4IntegratedAppPool" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" />
        <add name="Clr4ClassicAppPool" managedRuntimeVersion="v4.0" managedPipelineMode="Classic" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" />
        <add name="Clr2IntegratedAppPool" managedRuntimeVersion="v2.0" managedPipelineMode="Integrated" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" />
        <add name="Clr2ClassicAppPool" managedRuntimeVersion="v2.0" managedPipelineMode="Classic" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" />
        <add name="UnmanagedClassicAppPool" managedRuntimeVersion="" managedPipelineMode="Classic" autoStart="true" />
        <applicationPoolDefaults managedRuntimeLoader="v4.0">
            <processModel />
        </applicationPoolDefaults>
    </applicationPools>

    <sites>
        <site name="YourWebSite" id="2">
            <application path="/" applicationPool="Clr2IntegratedAppPool">
                <virtualDirectory path="/" physicalPath="C:\YourWebSite" />
            </application>
            <bindings>
                <binding protocol="http" bindingInformation="*:46397:localhost" />
            </bindings>
        </site>
    </sites>
</system.applicationHost>

理论上,您可以更改项目使用的池。我尝试过,但是没有帮助。可行的解决方案是删除.vs目录,然后再次打开您的解决方案。 .vs目录将使用正确的配置重新创建。

相关问题