Asp.net mvc 4 deployment error

I developed a web application in mvc 4. Everything works fine on a development machine, however on a real server this gives me the following error.

Failed to load file or assembly.

'System.Web.Http, Version = 4.0.0.0, Culture = Neutral, PublicKeyToken = 31bf3856ad364e35' or one of its dependencies. the module is expected to contain the assembly manifest.

I tried the following solutions:

  • Copied dll files to bin folder from my local drive
  • Checked that my hosting supports asp.net 4
  • Check if the web.config file is configured correctly.

Here is the exact screen trace. Please note that the last line shows .net version 4 and also asp.net version 4, so I assume this is not a problem. Please help me.

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 whole 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> 
+4
source share
2 answers

I finally managed to do it. Hope this also helps those who have similar problems.

The culprit is the publication master. I published my project using the publish tool. However, when I downloaded the published project, it simply did not work and showed that the assembly of system.web.http was damaged.

As I resolved it -

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

Other DLLs were also offered to me, and I did the same for everyone.

The application started to work as soon as I replaced all the failed DLLs with one of my bin folder.

I'm not sure if this is a mistake with the Visual Studio Publishing Wizard or not. If anyone has a better understanding of this issue, please send the help of others here.

+5
source

I had the same problem. Somehow publish the wizard did not like the release mode. In release mode, he was unable to deploy system.web.http.dll, and then also to build the razor. when I went into debug mode in the settings of the publication wizard, it finally worked. of course, this does not make it a solution - just the unpleasant job of publishing in debug mode. or use other publishing tools than the VS publishing wizard.

0
source

All Articles