升级到.Net 4.0后,我收到异常"无法加载文件或程序集'System.Windows,Version = 2.0.5.0'"

Ali*_*ned 6 asp.net-4.0

我们最近将我们的网络应用程序从3.5升级到4.0.现在我登录并加载带有Microsoft ScriptManager的页面后,我得到:

无法加载文件或程序集'System.Windows,Version = 2.0.5.0,Culture = neutral,PublicKeyToken = 7cec85d7bea7798e'或其依赖项之一.该系统找不到指定的文件.

它只是第一次发生,重新加载页面,一切正常.

更新:我们有所有Silverlight v4项目.我在C:\ Program Files\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0目录中找到了System.Windows.dll.为什么它会寻找2.0版?

这是整个异常(编辑和删除的文件夹路径)

'/ test'应用程序中的服务器错误.

无法加载文件或程序集'System.Windows,Version = 2.0.5.0,Culture = neutral,PublicKeyToken = 7cec85d7bea7798e'或其依赖项之一.该系统找不到指定的文件.

描述:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.

异常详细信息: System.IO.FileNotFoundException:无法加载文件或程序集'System.Windows,Version = 2.0.5.0,Culture = neutral,PublicKeyToken = 7cec85d7bea7798e'或其依赖项之一.该系统找不到指定的文件.

来源错误:

第450行:<UC5:PageTitle ID ="PageTitle"runat ="server"/>
第451行:<UC2:PageTabs ID ="testPageTabs"runat ="server"/>
第452行:<asp:ScriptManager ID ="ScriptManager1" runat ="server"/>
第453行:<div id ="step1Div"style ="padding-top:10px; padding-left:10px"runat ="server">
第454行:<asp:ValidationSummary ID ="displayValidationSummary" ValidationGroup ="displayCreateEditValidationGroup"runat ="server"/>

源文件: c:{directories}\Pages\Administration\DisplayCreateEdit.aspx行:452

程序集加载跟踪:以下信息有助于确定无法加载程序集"System.Windows,Version = 2.0.5.0,Culture = neutral,PublicKeyToken = 7cec85d7bea7798e"的原因.

警告:装配绑定日志记录已关闭.要启用程序集绑定失败日志记录,请将注册表值[HKLM\Software\Microsoft\Fusion!EnableLog](DWORD)设置为1.注意:程序集绑定失败日志记录会导致一些性能损失.要关闭此功能,请删除注册表值[HKLM\Software\Microsoft\Fusion!EnableLog].

堆栈跟踪:

[FileNotFoundException:无法加载文件或程序集'System.Windows,Version = 2.0.5.0,Culture = neutral,PublicKeyToken = 7cec85d7bea7798e'或其依赖项之一.系统找不到指定的文件.] System.ModuleHandle.ResolveType(RuntimeModule模块,Int32 typeToken,IntPtr*typeInstArgs,Int32 typeInstCount,IntPtr*methodInstArgs,Int32 methodInstCount,ObjectHandleOnStack类型)+0 System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module,Int32 typeToken,的RuntimeTypeHandle [] typeInstantiationContext,的RuntimeTypeHandle [] methodInstantiationContext)180 System.Reflection.RuntimeModule.ResolveType(的Int32 metadataToken,类型[] genericTypeArguments,类型[] genericMethodArguments)192 System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord,MetadataImport范围,


版本信息: Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.1

和web.config的system.web:

<system.web>
    <pages validateRequest="false" buffer="true" theme="Summer" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
        <controls>
            <add namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" tagPrefix="ajaxToolkit"/>
        </controls>
        <tagMapping>
            <add tagType="System.Web.UI.WebControls.TextBox" mappedTagType="CleanTextBox"/>
            <add tagType="System.Web.UI.HtmlControls.HtmlTextArea" mappedTagType="CleanTextArea"/>
        </tagMapping>
    </pages>
    <compilation debug="true" targetFramework="4.0">
        <assemblies>
        </assemblies>
    </compilation>
    <authentication mode="Forms">
        <forms requireSSL="false" cookieless="UseDeviceProfile" loginUrl="~/Pages/Authentication/Login.aspx" timeout="60" defaultUrl="~/Pages/Authentication/AccountHome.aspx" slidingExpiration="true" name="sqlAuthCookie" protection="All"/>
    </authentication>
    <sessionState timeout="60" mode="StateServer" stateConnectionString="tcpip=localhost" stateNetworkTimeout="60" cookieless="false"/>
    <customErrors mode="RemoteOnly" defaultRedirect="~/Pages/Global/DefaultError.aspx">
        <error statusCode="404" redirect="~/Pages/Global/404.htm"/>
        <error statusCode="403" redirect="~/Pages/Global/403.htm"/>
    </customErrors>
    <httpHandlers>
        <add path="*js.axd" verb="*" type="ScriptCompressorHandler"/>
        <add path="*css.axd" verb="*" type="CssCompressorHandler"/>
        <add path="*css" verb="*" type="CssCompressorHandler"/>
        <add verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
    </httpHandlers>
    <httpModules>
        <remove name="WindowsAuthentication"/>
        <remove name="PassportAuthentication"/>
        <remove name="AnonymousIdentification"/>
        <remove name="RoleManager"/>
        <remove name="Profile"/>
        <remove name="ErrorHandlerModule"/>
        <add type="ScriptCompressorModule" name="ScriptCompressorModule"/>
        <add type="CssCompressorModule" name="CssCompressorModule"/>
    </httpModules>
    <machineKey validationKey="{key}" decryptionKey="{key}" validation="SHA1"/>
    <httpRuntime maxRequestLength="1048576" executionTimeout="3600" requestValidationMode="2.0"/>
</system.web>
Run Code Online (Sandbox Code Playgroud)

在此处查看相同的问题Microsoft反馈/错误报告

编辑:我正在运行VS 2010,带有IIS 5.0的XP(我每天都想念Win 7 :-)).我们在本地IIS实例下运行Web应用程序,而不是Cassini.我们将它部署到测试服务器,我没有看到异常.我将C:\ Program Files\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\System.windows.dll安装到GAC后删除它并没有看到相同的异常,虽然我的同事没有这样做,偶尔也会看到它.我认为这只会在应用程序重新启动时发生(每当我们在本地开发时重建应用程序时都会发生这种情况).

3Da*_*ave 2

听起来您的解决方案中的项目之一正在引用 v2 系统程序集。确保所有项目和应用程序池都设置为使用 4.0。您可以在 Visual Studio 的项目属性中进行设置。

(请注意,如果您尚未使用新设置重建解决方案,则必须这样做)。