This incident occurred whilst creating a new ASP.NET 4.7.1 project in Visual Studio Enterprise 2017 (Version 15.5.2):
- Created a new ASP.NET Web Application (.NET Framework Standard 4.7.1) and enabled Web API;
- Added Flurl.Signed and Flurl.Http.Signed via the NuGet package manager;
- Updated all package dependencies.
Upon building and running the web application, an error occurred:
Could not load file or assembly ‘System.Net.Http, Version=4.0.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)
Here’s the source error:
Line 21: new { controller = “Help”, action = “Index”, apiId = UrlParameter.Optional });
Line 22:
Line 23: HelpPageConfig.Register(GlobalConfiguration.Configuration);
Line 24: }
Line 25: }
And the full stack trace:
[FileLoadException: Could not load file or assembly ‘System.Net.Http, Version=4.0.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.Http.GlobalConfiguration..cctor() +0
[TypeInitializationException: The type initializer for ‘System.Web.Http.GlobalConfiguration’ threw an exception.]
System.Web.Http.GlobalConfiguration.get_Configuration() +14
WebApplication1.Areas.HelpPage.HelpPageAreaRegistration.RegisterArea(AreaRegistrationContext context) in ..\WebApplication1\WebApplication1\Areas\HelpPage\HelpPageAreaRegistration.cs:23
System.Web.Mvc.AreaRegistration.CreateContextAndRegister(RouteCollection routes, Object state) +104
System.Web.Mvc.AreaRegistration.RegisterAllAreas(RouteCollection routes, IBuildManager buildManager, Object state) +190
System.Web.Mvc.AreaRegistration.RegisterAllAreas(Object state) +35
System.Web.Mvc.AreaRegistration.RegisterAllAreas() +7
WebApplication1.WebApiApplication.Application_Start() in ..\WebApplication1\WebApplication1\Global.asax.cs:16
[HttpException (0x80004005): The type initializer for ‘System.Web.Http.GlobalConfiguration’ threw an exception.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +475
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +176
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +349
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +303
[HttpException (0x80004005): The type initializer for ‘System.Web.Http.GlobalConfiguration’ threw an exception.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +658
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +89
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +188
After creating a few dummy projects and testing, I determined the adding references to Flurl.Signed / Flurl.Http.Signed and updating packages using the NuGet package manager added the following dependent assembly in the Web.Config file:
<dependentAssembly>
<assemblyIdentity name=”System.Net.Http” publicKeyToken=”b03f5f7f11d50a3a” culture=”neutral” />
<bindingRedirect oldVersion=”0.0.0.0-4.1.0.0″ newVersion=”4.1.0.0″ />
</dependentAssembly>
I understand what’s going on but not how to fix the dependency reference. I did find however that simply removing or commenting out the dependent assembly reference to “System.Net.Http” resolved the issue (at least presumably until another NuGet update is made).
Since I did not have this issue prior to updating Visual Studio 2017 from 15.5.1 to 15.5.2 last week, I’m making an educated guess that was the cause.
(more to come…)
Posted in ASP.NET, Programming, Windows