Strange issue with System.Net.Http 4.2.0.0 not found
See original GitHub issueI 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:
- Created 6 years ago
- Comments:10
Top GitHub Comments
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.
Thanks for sharing @thyams, appreciate your help.