4

我在 mvc 4 中开发了一个 Web 应用程序。在开发机器上一切都很好,但是在实时服务器上它给了我以下错误。

无法加载文件或程序集

'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 或其依赖项之一。该模块应包含程序集清单。

我尝试了以下解决方案:

  • 将 dll 文件从我的本地驱动器复制到 bin 文件夹
  • 检查我的主机是否启用了 asp.net 4
  • 已检查 web.config 文件是否已正确配置。

这是确切的屏幕跟踪。请注意,最后一行显示了 .net 版本 4 和 asp.net 版本 4,所以我认为这不是问题。请指导我。

Could not load file or assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The module was expected to contain an assembly manifest.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.BadImageFormatException: Could not load file or assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The module was expected to contain an assembly manifest.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.


WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Stack Trace: 


[BadImageFormatException: Could not load file or assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The module was expected to contain an assembly manifest.]
   innovationtimes.MvcApplication.Application_Start() +0

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

这是整个 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=169433
  -->
<configuration>
  <appSettings>
    <add key="webpages:Version" value="2.0.0.0"/>
    <add key="webpages:Enabled" value="false"/>
    <add key="PreserveLoginUrl" value="true"/>
    <add key="ClientValidationEnabled" value="true"/>
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
  </appSettings>
  <connectionStrings>
    <!--<add name="DataContext" providerName="System.Data.SqlClient" connectionString="Data Source=pc1\SQLEXPRESS;Initial Catalog=itdb;User Id=sa;Password=12345;"/>-->

  </connectionStrings>
  <system.web>
    <customErrors mode="Off"></customErrors>
    <compilation debug="true" targetFramework="4.0"/>
    <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>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>
    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit"/>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit"/>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0"/>
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0"/>
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
    </handlers>
  </system.webServer>
</configuration>
4

2 回答 2

5

我终于设法完成了。希望它也能帮助那些有类似问题的人。

罪魁祸首是发布向导。我使用发布工具发布了我的项目。但是,当我上传已发布的项目时,它根本无法正常工作并显示 system.web.http 程序集已损坏。

我是如何解决的-

我从项目的 bin 文件夹中上传了 system.web.http dll,以覆盖发布向导的 dll。

进一步提示我输入其他 dll,我对所有这些 dll 都做了同样的操作。

当我用我的 bin 文件夹中的一个替换所有错误的 dll 后,该应用程序就开始工作了。

我不确定这是否是 Visual Studio 发布向导的错误。如果有人对此问题有更好的了解,请在此处发布以寻求其他人的帮助。

于 2012-12-22T10:18:21.290 回答
0

我有同样的问题。不知何故,发布向导不喜欢发布模式。在发布模式下,它一直无法部署 system.web.http.dll,然后也无法进行 razor 组装。当我在发布向导设置中更改为调试模式时,它终于起作用了。当然,这并不能使它成为一个解决方案——只是在调试模式下发布的一个令人讨厌的工作。或者,使用 VS 发布向导以外的其他发布方式。

于 2013-04-14T06:10:27.003 回答