Reputation: 408
I am using .net framework 4.7.2 and installed System.Net.Http from nuget package. I am using simple asp.net forms application without any API packages. Application builds without any issue but when I run the application, I get below error.
Could not load file or assembly 'System.Net.Http' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Here is the full application trace
Server Error in '/' Application. Could not load file or assembly 'System.Net.Http' 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.Net.Http' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
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.Net.Http' could not be loaded.
=== Pre-bind state information === LOG: DisplayName = System.Net.Http (Partial) WRN: Partial binding information was supplied for an assembly: WRN: Assembly Name: System.Net.Http | Domain ID: 4 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:///G:/Projects/Sanganan/eClickShipNew/EasyPost.Web.UI/ LOG: Initial PrivatePath = G:\Projects\Sanganan\eClickShipNew\EasyPost.Web.UI\bin Calling assembly : (Unknown). === LOG: This bind starts in default load context. LOG: Using application configuration file: G:\Projects\Sanganan\eClickShipNew\EasyPost.Web.UI\web.config LOG: Using host configuration file: C:\Users\Dharmendra\Documents\IISExpress\config\aspnet.config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\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/Framework/v4.0.30319/Temporary ASP.NET Files/vs/67fd7ae1/97340337/System.Net.Http.DLL. LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/67fd7ae1/97340337/System.Net.Http/System.Net.Http.DLL. LOG: Attempting download of new URL file:///G:/Projects/Sanganan/eClickShipNew/EasyPost.Web.UI/bin/System.Net.Http.DLL. LOG: Using application configuration file: G:\Projects\Sanganan\eClickShipNew\EasyPost.Web.UI\web.config LOG: Using host configuration file: C:\Users\Dharmendra\Documents\IISExpress\config\aspnet.config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Redirect found in application configuration file: 4.1.1.3 redirected to 4.2.0.0. LOG: Post-policy reference: System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/67fd7ae1/97340337/System.Net.Http.DLL. LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/67fd7ae1/97340337/System.Net.Http/System.Net.Http.DLL. LOG: Attempting download of new URL file:///G:/Projects/Sanganan/eClickShipNew/EasyPost.Web.UI/bin/System.Net.Http.DLL. WRN: Comparing the assembly name resulted in the mismatch: Minor Version ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
Stack Trace:
[FileLoadException: Could not load file or assembly 'System.Net.Http' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
[FileLoadException: Could not load file or assembly 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)] 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.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +36
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +21 System.Reflection.Assembly.Load(String assemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38[ConfigurationErrorsException: Could not load file or assembly 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +728
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +196 System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +45
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +172
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +91 System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +111
System.Web.Compilation.BuildManager.ExecutePreAppStart() +156
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +695[HttpException (0x80004005): Could not load file or assembly 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 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) +659
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +89 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +188Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3190.0
here is the packages.config file
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AspNet.ScriptManager.jQuery" version="3.3.1" targetFramework="net471" />
<package id="AspNet.ScriptManager.jQuery.UI.Combined" version="1.12.1" targetFramework="net471" />
<package id="CommonServiceLocator" version="2.0.4" targetFramework="net471" />
<package id="DotNetOpenAuth.AspNet" version="4.3.4.13329" targetFramework="net471" />
<package id="DotNetOpenAuth.Core" version="4.3.4.13329" targetFramework="net471" />
<package id="DotNetOpenAuth.OAuth.Consumer" version="4.3.4.13329" targetFramework="net471" />
<package id="DotNetOpenAuth.OAuth.Core" version="4.3.4.13329" targetFramework="net471" />
<package id="DotNetOpenAuth.OpenId.Core" version="4.3.4.13329" targetFramework="net471" />
<package id="DotNetOpenAuth.OpenId.RelyingParty" version="4.3.4.13329" targetFramework="net471" />
<package id="EasyPost-Official" version="2.5.1" targetFramework="net472" />
<package id="EnterpriseLibrary.Common" version="6.0.1304.0" targetFramework="net471" />
<package id="EnterpriseLibrary.Logging" version="6.0.1304.0" targetFramework="net471" />
<package id="EntityFramework" version="6.2.0" targetFramework="net471" />
<package id="iTextSharp" version="5.5.13" targetFramework="net471" />
<package id="jQuery" version="3.3.1" targetFramework="net471" />
<package id="jQuery.UI.Combined" version="1.12.1" targetFramework="net471" />
<package id="Microsoft.AspNet.Membership.OpenAuth" version="2.0.1" targetFramework="net471" />
<package id="Microsoft.AspNet.Providers.Core" version="2.0.0" targetFramework="net471" />
<package id="Microsoft.AspNet.Providers.LocalDB" version="2.0.0" targetFramework="net471" />
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net471" />
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net471" />
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net471" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />
<package id="Modernizr" version="2.8.3" targetFramework="net471" />
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net471" />
<package id="RestSharp" version="106.5.2" targetFramework="net471" />
<package id="System.Buffers" version="4.5.0" targetFramework="net472" />
<package id="System.Configuration.ConfigurationManager" version="4.5.0" targetFramework="net471" />
<package id="System.IO" version="4.3.0" targetFramework="net471" />
<package id="System.Memory" version="4.5.1" targetFramework="net472" />
<package id="System.Net.Http" version="4.3.4" targetFramework="net472" />
<package id="System.Net.Http.Formatting.Extension" version="5.2.3.0" targetFramework="net472" />
<package id="System.Net.Http.WinHttpHandler" version="4.5.1" targetFramework="net472" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
<package id="System.Reflection.Emit" version="4.3.0" targetFramework="net471" />
<package id="System.Runtime" version="4.3.0" targetFramework="net471" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net472" />
<package id="System.Security.AccessControl" version="4.5.0" targetFramework="net471" />
<package id="System.Security.Cryptography.Algorithms" version="4.3.1" targetFramework="net471" />
<package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net471" />
<package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net471" />
<package id="System.Security.Cryptography.X509Certificates" version="4.3.2" targetFramework="net471" />
<package id="System.Security.Permissions" version="4.5.0" targetFramework="net471" />
<package id="System.Security.Principal.Windows" version="4.5.1" targetFramework="net471" />
<package id="Unity" version="5.8.11" targetFramework="net471" />
<package id="Unity.Abstractions" version="3.3.1" targetFramework="net471" />
<package id="Unity.Interception" version="5.5.5" targetFramework="net471" />
</packages>
Upvotes: 1
Views: 2475
Reputation: 266
If you are targeting .NET Framework then you shouldn't need to reference System.Net.Http via a NuGet package. Instead, you should be referencing the framework's System.Net.Http which you can do by right-clicking the References -> Add Reference... and selecting System.Net.Http from the Assemblies -> Framework list.
Upvotes: 1
Reputation: 13227
I had the similar issue. In my case the reference to System.Net.Http
pointed to some other .dll
than .dll
in the packages
folder. Try to check that the reference is really pointing to the .dll
file from packages
folder
Upvotes: 0