4

I have developed a web application in mvc 4. Everything is fine on the development machine, however on the live server it is giving me the following error.

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.

I have tried the following solutions:

  • Copied dll files to the bin folder from my local drive
  • Checked that my hosting has asp.net 4 enabled
  • Have checked that web.config file is properly configured.

Here is the exact screen trace. Notice that the last line shows .net version 4 as well as asp.net version 4 so I assume it is not the problem. Please guide me on it.

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

Here is the entire web.config file

 <?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>
7
  • If it features System.Web.Http, could you post the configuration/runtime/assemblyBinding section of your web.config ? Commented Dec 18, 2012 at 14:26
  • I have edited the question. Please go through it Commented Dec 18, 2012 at 14:37
  • Try: Expand Reference > Right click on selected reference > Go to Properties > Set Copy Local = true. Do it for all of them. It could be deployment server missing something. Commented Dec 18, 2012 at 14:38
  • @Kaf - Have tried it. Same issue. Commented Dec 18, 2012 at 14:43
  • 1
    System.Web.Http.dll should be loaded into the GAC when MVC4 is installed. You should verify that MVC4 is properly installed on the destination machine and that this library has made it into the GAC. Commented Dec 18, 2012 at 14:45

2 Answers 2

5

I finally managed to get it done. Hope it will also help those with similar issues.

The culprit is publish wizard. I published my project using the publish tool. However when I uploaded the published project, it was simply not working and showing the system.web.http assembly is corrupt.

How did I resolved it -

I uploaded the system.web.http dll from the bin folder of my project to overwrite the dll of publish wizard.

I was further prompted for other dlls and I did same for all of them.

The application started working as soon as I replaced all the erroneous dlls with one from my bin folder.

I am not sure if it is a bug with visual studio publish wizard or not. if Anybody have better idea of this issue, please post here for help of others.

Sign up to request clarification or add additional context in comments.

1 Comment

yes, but this solution doesn't solve the wizard deploying issue. Unfortunately I am facing with the same issue, first of all I thought its all because of UAC - nop, then folder rights? I have looked to file permissions, all looks good. What I might tried is to remove/add the reference one more time and rebuild the installer(msi) - no success too. Any idea?
0

I had the same problem. Somehow publish wizard did not like Release mode. In release mode, it kept failing to deploy system.web.http.dll and then also for razor assembly. when I changed to debug mode in publish wizard settings, it finally worked. of course, that doesn't make it a solution - just a nasty work around of publishing in debug mode. or else, use some other means of publishing than the VS publish wizard.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.