Could not load file or assembly System.Web.Http.WebHost
I'm running my application on an IIS server, but now I want to do some debugging with breakpoints etc, so I decided to run from Visual Studio to IIS Express. But, when I start running my application I receive this error:
Server Error in '/' Application.
Could not load file or assembly 'System.Web.Http.WebHost, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
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.FileLoadException: Could not load file or assembly 'System.Web.Http.WebHost, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Source Error:
Line 13:
Database.SetInitializer(new TodoListServiceInitializer()); Line 14:
GlobalConfiguration.Configure(WebApiConfig.Register); Line 15:
} Line 16: } Line 17: }
Source File: C:developspl_developmentmainDocksDocks_SensorGlobal.asax.cs
Line: 15
Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.Http.WebHost, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.
=== Pre-bind state information === LOG: DisplayName = System.Web.Http.WebHost, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 (Fully-specified) LOG: Appbase = file:///C:/develop/Spl_Development/Main/Docks/Docks_Sensor/ LOG: Initial PrivatePath = C:developSpl_DevelopmentMainDocksDocks_Sensorbin Calling assembly : Docks.Sensor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. === LOG: This bind starts in default load context. LOG: Using application configuration file: C:developSpl_DevelopmentMainDocksDocks_Sensorweb.config LOG: Using host configuration file: C:UsersligthartDocumentsIISExpressconfigaspnet.config LOG: Using machine configuration file from C:WindowsMicrosoft.NETFrameworkv4.0.30319configmachine.config. LOG: Post-policy reference: System.Web.Http.WebHost, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/25aafd2f/29cb2bd3/System.Web.Http.WebHost.DLL. LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/25aafd2f/29cb2bd3/System.Web.Http.WebHost/System.Web.Http.WebHost.DLL. LOG: Attempting download of new URL file:///C:/develop/Spl_Development/Main/Docks/Docks_Sensor/bin/System.Web.Http.WebHost.DLL. WRN: Comparing the assembly name resulted in the mismatch: Build Number ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
Stack Trace:
[FileLoadException: Could not load file or assembly 'System.Web.Http.WebHost, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
Docks.Sensor.WebApiApplication.Application_Start() in C:developspl_developmentmainDocksDocks_SensorGlobal.asax.cs:15
[HttpException (0x80004005): Could not load file or assembly 'System.Web.Http.WebHost, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9966013
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +352
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
[HttpException (0x80004005): Could not load file or assembly 'System.Web.Http.WebHost, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9947380 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +261
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1055.0
I've seen a lot of questions, but can't really seem to find an answer to this problem. I went looking if any of the required files or references were missing.. but no:
References:
bin folder:
version:
I have tried to remove the bin folder, everything.. I just can't seem to get it working. I hope there's a solution, thanks in advance!
删除System.Web.Http.WebHost.dll并添加旧版本4.0.0.0
I had the same issue and tried the solution provided by Hetal. But now it gives error in global.asax.cs in GlobalConfiguration.Configure(WebAPICOnfig.Register) that it doesn't exist in the library.
链接地址: http://www.djcxy.com/p/72718.html