4
votes

Getting an

Could not load file or assembly 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified." exception after publishing to Azure as an App Service.

I have created a ASP.NET Wep API application using Entity Framework DB First approach. I did not use any NuGet package to install System.Net.Http, it was added automatically when the project was created. The latest version is 4.2.0.0.

It works fine when I run on my local IIS (IIS Express).

I published this app as an Azure App Service successfully but it does not open the API Home page. Instead I get the above mentioned exception.

I tried using bindingRedirect in Web.config but it does not help.

I am new to Azure and not sure how the dlls are deployed. Any help is greatly appreciated.

2

2 Answers

1
votes

Upgraded project to 4.7.2.

Turns out Visual Studio 2017, when installing the .NET 4.3.3 Nuget package for System.Net.HTTP is also adding DLL reference from the GAC. This in tandem with an Assembly redirect causes run time System.IO.FileNotFoundException looking for version 4.2.0.0 of System.Net.Http.

The good news, is to add references, uncheck System.Net.Http from the GAC (which was added automatically or by other developers in the project at one point in time), and simply delete the Assembly redirect.

For more details, you could refer to this article.

0
votes

I think found the cause of the issue. My project is using .Net framework version 4.7.2 and on Azure the app service is using .Net framework version 4.7. So changing the target framework in my project properties to 4.7 seems to work.