could not load file or assembly System.Net.Http


I am really stuck on this one and could use some help.

This problem started when I added an async method involving httpclient to a class library. I call the class library from a short test console application. When it gets to the async method I get an exception:

System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Net.Http, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'

Originally it said Could not load System.Net.Http Version (I had version in the project) and I was using Framework 4.5.2. I could not find a version for NET Framework 4.5.2 so I first updated the class library and test projects to NFW 4.7.2 and then added a reference to the version of System.Net.Http associated with this framework (i.e. choosing it from the assemblies tab).

When I look at the properties of the dll in the class lib project (toolslib) it shows I added the same reference to the test project used to call it and it also now shows

Additionally I added a redirect section to the app.config for toolslib

        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a"  culture="neutral"/>
        <bindingRedirect oldVersion="" newVersion=""/>

I put the same lines in the app.config for the test console app.

However I still get the same issue now with it saying it can't load I set up Fusion Logs and got the following after running and getting the exception:

*** Assembly Binder Log Entry  (7/9/2020 @ 9:12:52 PM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Users\smjhu\Documents\DevProjects\IDXUtil\Test\bin\Debug\Test.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = System.Net.Http, Version=, Culture=neutral,  ]PublicKeyToken=b03f5f7f11d50a3a
LOG: Appbase = file:///C:/Users/smjhu/Documents/DevProjects/IDXUtil/Test/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = Test.exe
Calling assembly : ToolsLib, Version=, Culture=neutral, PublicKeyToken=null.
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\smjhu\Documents\DevProjects\IDXUtil\Test\bin\Debug\Test.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: redirected to
LOG: Post-policy reference: System.Net.Http, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Users/smjhu/Documents/DevProjects/IDXUtil/Test/bin/Debug/System.Net.Http.DLL.
LOG: Attempting download of new URL file:///C:/Users/smjhu/Documents/DevProjects/IDXUtil/Test/bin/Debug/System.Net.Http/System.Net.Http.DLL.
LOG: Attempting download of new URL file:///C:/Users/smjhu/Documents/DevProjects/IDXUtil/Test/bin/Debug/System.Net.Http.EXE.
LOG: Attempting download of new URL file:///C:/Users/smjhu/Documents/DevProjects/IDXUtil/Test/bin/Debug/System.Net.Http/System.Net.Http.EXE.
LOG: All probing URLs attempted and failed.

The only thing I can see from the logs is it appears to be attempting to look for the dll in the test/bin/debug folder.

I tried setting the dll to copy local but same result.

I then tried copying the dll into the bin/debug folder manually but then when I hit that method I get a badimage exception saying I cannot use reference assemblies.

BTW also tried updating with nuget with same result

asked on Stack Overflow Jul 10, 2020 by smjhunt

1 Answer


If I remove the bindingredirect from the console app, the problem goes away.

Unfortunately, this does not really provide an explanation for the problem but it does at least for now resolve it.

answered on Stack Overflow Jul 10, 2020 by smjhunt

User contributions licensed under CC BY-SA 3.0