Asp.Net Hosting Issues: Could not load file or assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

StackOverflow https://stackoverflow.com/questions/21461242

سؤال

I worked on an Asp.Net MVC4 application on my personal desktop and trying to host it into a windows server 2012 and IIS8 by remotely logging into it using the normal deployment procedure and Finally When I tried to browse it threw me a server error as follows:

Server Error in '/' Application.
--------------------------------------------------------------------------------


Could not load file or assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. 
  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.IO.FileNotFoundException: Could not load file or assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

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: 



[FileNotFoundException: Could not load file or assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
   MvcApplication1.MvcApplication.Application_Start() +0

[HttpException (0x80004005): Could not load file or assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +12864673
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +175
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475

[HttpException (0x80004005): Could not load file or assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12881540
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12722601

May I know where I id a mistake

هل كانت مفيدة؟

المحلول

Simply, you have not deployed necessary assembly references to work on host properly! And it tries to search, perhaps on hosting provider system while is not accessible! Follow these steps to make sure you have added required files due to deployment.

Edit: Therefore, while this option(add deployable dependencies) still exists in Visual Studio 2010 (and Visual Studio 2010 SP1), it was built into the NuGet Package Manager alongside Visual Studio 2012 so that all required assemblies are automatically bin deployed.

نصائح أخرى

The specific assembly that you're missing in this case is the Web API 2.1 WebHost (or 2.2 now). Just add that using the Nuget Package Console to your project and then rebuild.

Try to add the Web API 2.1 WebHost to your project using the Nuget Package Manager and then rebuild, publish and deploy on IIS.

You can fixed by either of below steps:
Option 1: To Resolve issue you have to move “System.Web.Http.WebHost.dll” file in “bin” folder to IIS. And restart the server to reload everything again. Check the site should work.

Option 2: Follow below steps:
1) Go to “Solution Explorer” in Visula Studio.
2) Right Click on “System.Web.Http.WebHost” in “References” and select properties.
3) Update property “Local Copy” to “True”.
4) Clear and Build again to have DLL in bin folder.
5) Copy the “System.Web.Http.WebHost.dll” file in “bin” folder to IIS.
Application should work.

Source: http://sforsuresh.in/not-load-file-assembly-system-web-http-webhost/

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top