Facing "Could not load file or assembly 'System.Web.Http.WebHost, Version=4.0.0.0, ' or one of its dependencies." [duplicate] - asp.net-mvc-4

This question already has answers here:
Could not load file or assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35'
(8 answers)
Closed 5 years ago.
I am trying to deploy a MVC Web API solution on the server. The server has Windows 2012 R2 operating system. This is MVC 4 based Web API solution.
The server has .Net 4.0 framework installed. Except this server machine the solution has been deployed and working fine as expected. NOTE: those other machines has Visual Studio installed.
My issue here is - no matter whichever method I am applying, either solution itself or publish the solution, it is not working and giving below error.
Could not load file or assembly 'System.Web.Http.WebHost, 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.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
The stack trace says:
[FileNotFoundException: Could not load file or assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
OSCARService.WebApiApplication.Application_Start() +0
[HttpException (0x80004005): Could not load file or assembly 'System.Web.Http.WebHost, 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) +544
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +186
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +402
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +343
[HttpException (0x80004005): Could not load file or assembly 'System.Web.Http.WebHost, 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) +579
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +112
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +716
I tried finding this file (System.Web.Http.WebHost) in the framework directory but am unable to find this specific file.
I wonder Is this file necessarily required to be available physically?
I also tried setting System.Web.Http DLL to "CopyLocal='True'" but didn't work.
I already tried looking for similar situation/questions-answers here, but couldn't really get any direction.
I'd appreciate if anyone could provide direction here to my issue.

I fixed this by reinstalling the NuGet package, which corrects broken dependencies. From the package manager, try running this command
Update-Package Microsoft.AspNet.WebApi -reinstall

Check the bin folder of your deployed project. It should contain System.Web.Http.WebHost.dll. If this dll is in this folder, check the version. If it isn't 4.0.0.0, then you should deploy version 4.0.0.0. If you are using nuget packages, check your packages.config else check your web.config if you have the right version installed.
Hope this helps

Related

Getting an Unexpected Error in dotnet core Project

In my solution Explorer(Visual Studio) there are 5 projects
DigiIdentity(webapi)
Core(class library)
Data(class library)
Services(class library)
DigiPigmyApi(webapi)
DigiSyncApi(webapi)
I am getting following error while running the project(solution)
Error CS1705 Assembly 'Microsoft.AspNetCore.Hosting' with identity 'Microsoft.AspNetCore.Hosting, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' uses 'Microsoft.AspNetCore.Hosting.Abstractions, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' which has a higher version than referenced assembly 'Microsoft.AspNetCore.Hosting.Abstractions' with identity 'Microsoft.AspNetCore.Hosting.Abstractions, Version=1.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
Actually I am not finding the Microsoft.AspNetCore.Hosting.Abstractions, Version=1.1.1.0 package anywhere, can any one tell me the exact course of the error.

Loading a DLL in the GAC

currently I have a problem with getting a DLL into the Windows GAC. I tried to follow the steps of creating a DLL and loading it as described in this blog post:
http://blogs.technet.com/b/cloudpfe/archive/2014/02/01/how-to-create-a-custom-authentication-provider-for-active-directory-federation-services-3-0-part-2.aspx
At the point where I try calling the following command:
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7514a164b89fa979")
I get an error which tells me that System.EnterpriseServices could not be found:
Exception calling "Load" with "1" argument(s): "Could not load file or
assembly 'System.EnterpriseServices, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=7514a164b89fa979' or one of its dependencies. The
system cannot find the file specified."
The specified DLL (System.EnterpriseServices) does exist* on the machine.
So now my question is, why can't this method find the DLL and what do I have to do/change to get this command to work?
NOTE: I Tried this on a vanilla Windows Server 2012 R2 with just ADFS parts installed; And I've called the command from the Powershell.
*UPDATE: The System.EnterpriseServices DLL resides in
C:\Windows\Microsoft.NET\assembly\GAC_64\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a
and
C:\Windows\WinSxS\amd64_system.enterpriseservices_b03f5f7f11d50a3a_4.0.9600.1638‌​4_none_53a3f9b13fac0ba5\
So it should be available from the GAC.
I think your public Key token is incorrect, you found your own answer with your update :) .
It should be
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
Give this a try.

SolrNET Ninject Integration Error- Could not load file or assembly 'HttpWebAdapters'

I had successfully implemented Solrnet using Ninject Integration. However it suddenly started failing yesterday giving the following error.
Could not load file or assembly 'HttpWebAdapters, Version=0.4.0.2002, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
Here is the stack trace:
[FileNotFoundException: Could not load file or assembly 'HttpWebAdapters, Version=0.4.0.2002, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.]
SolrNet.Impl.SolrConnection..ctor(String serverURL) +0
Ninject.Integration.SolrNet.SolrNetModule.Load() in c:\Users\kanja-1\Documents\Visual Studio 2012\Projects\Ninject.Integration.SolrNet\Ninject.Integration.SolrNet\SolrNetModule.cs:205
Ninject.Modules.NinjectModule.OnLoad(IKernel kernel) in c:\Projects\Ninject\ninject\src\Ninject\Modules\NinjectModule.cs:85
Ninject.KernelBase.Load(IEnumerable1 m) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:217
Ninject.KernelBase..ctor(IComponentContainer components, INinjectSettings settings, INinjectModule[] modules) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:100
Ninject.KernelBase..ctor(INinjectModule[] modules) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:57
Ninject.StandardKernel..ctor(INinjectModule[] modules) in c:\Projects\Ninject\ninject\src\Ninject\StandardKernel.cs:46
MealsToGo.App_Start.NinjectWebCommon.CreateKernel() in c:\Users\kanja-1\Documents\Visual Studio 2012\Projects\MealsToGo\MealsToGo\App_Start\NinjectWebCommon.cs:53
Ninject.Web.Common.Bootstrapper.Initialize(Func1 createKernelCallback) in c:\Projects\Ninject\Ninject.Web.Common\src\Ninject.Web.Common\Bootstrapper.cs:50
MealsToGo.App_Start.NinjectWebCommon.Start() in c:\Users\kanja-1\Documents\Visual Studio 2012\Projects\MealsToGo\MealsToGo\App_Start\NinjectWebCommon.cs:34
[TargetInvocationException: Exception has been thrown by the target of an invocation.]
Does someone know what I need to do to fix this?
thanks

Windows Azure intermittent Identity error when parsing webconfig

This issue happens seemingly randomly after publishing.
The site will work fine and then bam, I get this error parsing the webconfig. I just republish and it works fine for a bit again. When publishing, I checked the box to remove existing files so there shouldn't be garbage laying around.
This is an MVC4 project using .net 4.5 and Azure Access Control Service (ACS) integrated with Yahoo!. This error occurs when redirecting back from Yahoo. This way happening every time, but I found a post (which I can not find now, of course) where there was a bug with the 4.5.1 Identity and Access Visual Studio integration. I went to the previous version and now it's only sometimes.
ID8030: The value of the 'type' property could not be parsed.
Verify that the type attribute of '<issuerNameRegistry type="System.IdentityModel.Tokens.ValidatingIssuerNameRegistry, System.IdentityModel.Tokens.ValidatingIssuerNameRegistry"><authority name="[my authority]"><keys><add thumbprint="[print]" /></keys><validIssuers><add name="[issuer]" /></validIssuers></authority></issuerNameRegistry>' element is correct.
In the above error message, I have replaced the items in brackets ([]) for this post.
Here is the stack trace:
[TypeLoadException: ID8030: The value of the 'type' property could not be parsed. *** element is correct.]
System.IdentityModel.Configuration.TypeResolveHelper.Resolve(ConfigurationElementInterceptor customTypeElement, Type customType) +602659
System.IdentityModel.Configuration.IdentityConfiguration.GetIssuerNameRegistry(IssuerNameRegistryElement element) +114
System.IdentityModel.Configuration.IdentityConfiguration.LoadHandlerConfiguration(IdentityConfigurationElement element) +841
System.IdentityModel.Configuration.IdentityConfiguration.LoadConfiguration(IdentityConfigurationElement element) +117
System.IdentityModel.Configuration.IdentityConfiguration..ctor(String identityConfigurationName) +180
System.IdentityModel.Services.Configuration.FederationConfiguration.LoadConfiguration(FederationConfigurationElement element) +392
System.IdentityModel.Services.Configuration.FederationConfiguration..ctor(Boolean loadConfig) +94
System.IdentityModel.Services.FederatedAuthentication.CreateFederationConfiguration() +71
System.IdentityModel.Services.FederatedAuthentication.get_FederationConfiguration() +85
System.IdentityModel.Services.HttpModuleBase.Init(HttpApplication context) +56
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +418
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
[HttpException (0x80004005): ***... element is correct.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9873784
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
I had the same issue when running local. I was going through the How-To found here: http://msdn.microsoft.com/en-us/library/jj161104.aspx and would get the type not found error on that assembly.
I double checked to make sure I pulled down the assembly via NuGet and even uninstalled and reinstalled it... no dice. It basically boiled down to a missing reference to the System.IdentityModel.Tokens.ValidatingIssuerNameRegistry
So, if you did pull this down via NuGet and you still have the issue, remember that when NuGet drops this package, it will throw it in a packages folder that's at the solution level in the file system.
If your project doesn’t show a reference to System.IdentityModel.Tokens.ValidatingIssuerNameRegistry, add the assembly to your project by right clicking the project, select Add Reference, Browse, then click the Browse button and then browse up to the packages folder and find the dll ([Your Solution Root]packages\System.IdentityModel.Tokens.ValidatingIssuerNameRegistry.4.5.1\lib\net45) and add it.
I hope this helps.
I ran into the same issue but it was constant for me, not sporadic, so perhaps a different underlying root issue.
I was able to fix the issue though by installing the following NuGet package in my MVC 4 project:
http://www.nuget.org/packages/System.IdentityModel.Tokens.ValidatingIssuerNameRegistry/
I can't remember if this was added by default in a new MVC 4 project. I did at one point remove it so perhaps it may have been removing then reinstalling that resolved the issue. Either way, by adding the package above back I was able to get my MVC 4 project working with ACS correctly.
Hope it works for you as well.
I just had the same problem. One way to solve it is to add a reference to the DLL specified in the other posts.
Another option is to replace the section with this one, that uses a class available in the core .Net Framework 4.5 (you must add a reference to System.IdentityModel too):
<issuerNameRegistry type="System.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<trustedIssuers>
<add thumbprint="[print]" name="[issuer]" />
</trustedIssuers>
</issuerNameRegistry>

What would cause a 'could not load file or assembly' error concerning 'Microsoft.WindowsAzure.Configuration'?

I have a multi-tier Azure application I've been working on. It uses web and worker roles behind an MVC front end, as well as Azure SQL and Table storage. It has been working well for a while, both in the emulator and the cloud.
I've just started adding some Service Bus functionality to it, adding the Service Bus package from NuGet, and now I find that although everything still compiles, I am getting the following runtime error:
Server Error in '/' Application.
Could not load file or assembly 'Microsoft.WindowsAzure.Configuration' or one of its dependencies. Strong name signature could not be verified. The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)
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 'Microsoft.WindowsAzure.Configuration' or one of its dependencies. Strong name signature could not be verified. The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)
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 'Microsoft.WindowsAzure.Configuration' could not be loaded.
=== Pre-bind state information ===
LOG: User = JCFXLAPTOP\User
LOG: DisplayName = Microsoft.WindowsAzure.Configuration
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Microsoft.WindowsAzure.Configuration | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///D:/Work/CLIENTS/PageEngine/Solutions/PageEngine/Web.PageEngine/
LOG: Initial PrivatePath = D:\Work\CLIENTS\PageEngine\Solutions\PageEngine\Web.PageEngine\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\Work\CLIENTS\PageEngine\Solutions\PageEngine\Web.PageEngine\web.config
LOG: Using host configuration file: C:\Program Files\IIS Express\config\templates\PersonalWebServer\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/4904ccbc/14659c77/Microsoft.WindowsAzure.Configuration.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/root/4904ccbc/14659c77/Microsoft.WindowsAzure.Configuration/Microsoft.WindowsAzure.Configuration.DLL.
LOG: Attempting download of new URL file:///D:/Work/CLIENTS/PageEngine/Solutions/PageEngine/Web.PageEngine/bin/Microsoft.WindowsAzure.Configuration.DLL.
LOG: Using application configuration file: D:\Work\CLIENTS\PageEngine\Solutions\PageEngine\Web.PageEngine\web.config
LOG: Using host configuration file: C:\Program Files\IIS Express\config\templates\PersonalWebServer\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Microsoft.WindowsAzure.Configuration, Version=1.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
ERR: Failed to complete setup of assembly (hr = 0x80131045). Probing terminated.
Stack Trace:
[FileLoadException: Could not load file or assembly 'Microsoft.WindowsAzure.Configuration' or one of its dependencies. Strong name signature could not be verified. The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)]
[FileLoadException: Could not load file or assembly 'Microsoft.WindowsAzure.Configuration, Version=1.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Strong name signature could not be verified. The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +210
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +242
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +17
System.Reflection.Assembly.Load(String assemblyString) +35
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +122
[ConfigurationErrorsException: Could not load file or assembly 'Microsoft.WindowsAzure.Configuration, Version=1.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Strong name signature could not be verified. The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +12731430
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +503
System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +142
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +334
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +203
System.Web.Compilation.BuildManager.ExecutePreAppStart() +152
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1151
[HttpException (0x80004005): Could not load file or assembly 'Microsoft.WindowsAzure.Configuration, Version=1.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Strong name signature could not be verified. The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12847312
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12675965
I noticed that the ServiceBus NuGet package references a newer version of the Microsoft.WindowsAzure.Configuration dll (1.7.0.2), and wondered if that might be the cause. I've tried overriding this and changing all references to either 1.7.0.0 or 1.7.0.2 - neither change helped. I've also tried removing all Azure references from the solution and re-adding references by installing NuGet packages and referencing the latest SDK. This hasn't helped either.
I should add that at all times the Microsoft.WindowsAzure.Configuration dll has been in the bin folder of the MVC application, and that it has always had CopyLocal set to true.
I note that the Azure Configuration NuGet package was updated very recently (Friday 27th July), and I wonder if that might have something to do with it.
Does anybody know what the issue could be?
EDIT
Just to confirm that removing the service bus nuget package fixes the problem. Reinstating it causes the problem to recur. I don't know if this matters but the Microsoft.WindowsAzure.Configuration dll added as part of the NuGet package seems to have an inconsistent version number. While the path suggests the version should be 1.7.0.2:
D:\Work\CLIENTS\PageEngine\Solutions\PageEngine\packages\Microsoft.WindowsAzure.ConfigurationManager.1.7.0.2\lib\net35-full\Microsoft.WindowsAzure.Configuration.dll
... the version number in the properties inspector is still 1.7.0.0
This was an issue with the Microsoft.WindowsAzure.Configuration assembly, version 1.7.0.2
Temporarily fixed by rolling back to either 1.7.0.1 or 1.7.0.0 and then permanently fixed in 1.7.0.3
Had same problem. I reverted Microsoft.WindowsAzure.ConfigurationManager back to NuGet version 1.7.0.1. Now it is working OK.