question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Strange issue with System.Net.Http 4.2.0.0 not found

See original GitHub issue

I have a strange issue, which drives me crazy…

I have a simple Class Library Project (Full .NET Framework, 4.6.1) with a wrapper class for functionality around Cosmos DB. Therefore I have added the “Microsoft.Azure.DocumentDB” NuGet Package 1.19.1 to this project. Other than that, I have a reference to the “Newtonsoft.Json” NuGet Package 10.0.3, as well as to a couple of “Microsoft.Diagnostics.EventFlow.*” NuGet Packages.
So far, everything compiles without any error.

But as soon as I hit my wrapper class – consumed from a simple Service Fabric Stateless Service (Full .NET Framework 4.6.1) – and try to execute the following line of code: _docClient = new DocumentClient(new Uri(cosmosDbEndpointUrl), cosmosDbAuthKey); I get this strange error at runtime:

System.IO.FileNotFoundException occurred HResult=0x80070002 Message=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. Source= StackTrace: at Microsoft.Azure.Documents.Client.DocumentClient.Initialize(Uri serviceEndpoint, ConnectionPolicy connectionPolicy, Nullable1 desiredConsistencyLevel) at Microsoft.Azure.Documents.Client.DocumentClient…ctor(Uri serviceEndpoint, String authKeyOrResourceToken, ConnectionPolicy connectionPolicy, Nullable1 desiredConsistencyLevel) Inner Exception 1: FileNotFoundException: Could not load file or assembly ‘System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The system cannot find the file specified.

I have absolutely no clue, why the System.Net.Http assembly is not found at all – there is no direct assembly reference in my class library project to the .Net Framework Assembly “System.Net.Http”. What I also do not understand is, that there is this weird binding redirect to 4.2.0.0 – where is that one coming from? To get around this one, I tried to add the following redirect to the app.config of the Service Fabric Service (which is consuming the class library).

In a Service Fabric Service without any of the EventFlow NuGet Packages I have no runtime error at all, everything works as expected. From that, my assumption is about the .NETStandard references being pulled in through the EventFlow Packages. So somehow the mixture of .NET 4.6.1 full Framework and .NETStandard causes this issue.

Any clue?

Thanks and regards, OliverB

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10

github_iconTop GitHub Comments

3reactions
houseofcatcommented, Jul 16, 2018

Not a reopen request but the issue can still happen but I have a work around.

Upgraded project to 4.7.2. Went through all the bells and whistles necessary.

Go to run finally and get the File not found exception looking for a 4.2.0.0 version of System.Net.Http…

Turns out Visual Studio 2017, when installing the .NET 4.3.3 Nuget package for System.Net.HTTP is also adding DLL reference (old school) 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.

Issue was gone after that.

1reaction
karolz-mscommented, Jul 16, 2018

Thanks for sharing @thyams, appreciate your help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Strange issue with System.Net.Http 4.2.0.0 not found
Http assembly is not found at all – there is even a assembly reference in my class library project to the .Net Framework...
Read more >
Could not load file or assembly 'System.Net.Http, Version= ...
I am utilizing the Coinbase project by Brian Chavez @bchavez, which itself depends on Flurl and Flurl.Http. I am 100% sure I have...
Read more >
net – Strange issue with System.Net.Http 4.2.0.0 not found
I have a strange issue, which drives me crazy… I have a simple Class Library Project (Full .NET Framework, 4.6.1) with a wrapper...
Read more >
Solution- Could not load file or assembly 'System.Net.Http ...
The system cannot find the file specified. ... Net.Http assembly with version 4.2.0.0 & when it fails to locate the desired version, ...
Read more >
ASP.NET error with System.Net.Http 4.2.0.0 : r/dotnet
I am getting ASP.NET 4.0 errors every 1-2 minutes in the Event logs on all our SCCM distribution points since enabling MCC/DOINC and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found