Search code examples
.netmicrosoft-graph-api

Unable to run C# application with Microsoft Graph 3.2.0 due to issues with system.net.http missing reference


system.net.http
  • NuGet: 4.3.4 -> 4.0.30319 -> 4.1.1.3
  • NuGet: 4.3.3 -> 4.0.30319 -> 4.1.1.2
  • NuGet: 4.3.2 -> 4.0.30319 -> 4.1.1.1
  • Framework: 4.6.2 > 4.0.30319 -> 4.0.0.0

enter image description here

Now, if I change my project settings like this to 4.7.2:

enter image description here

And then examine my system.net.http assembly:

enter image description here

  • Framework: 4.7.2 > 4.0.30319 -> 4.2.0.0

So the above research implies that if I want system.net.http I need to use the .NET Framework 4.7.2. OK so far. But ...

Microsoft Graph 3.2.0 When you look at the dependencies for Microsoft Graph 3.2.0 it says:

enter image description here

So it is stating that it depends on .NET Framework 4.6.1 right?

So I uninstall and re-install several NuGet Packages so that they are right for 4.7.2 and then I modify my app.config entry:

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

Now it compiles. Yet, when I run the software I still except this exception (found everywhere on the internet!):

{"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.":"System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"}

That file I believe is here:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net471\lib

That is the one used during complilation.

Yet when I try to find the runtime path to this DLL all I can find is:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319

But the file in there is dated 19/03/2019 with a file version of 4.8.3752.0. Yet the one in here:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net471\lib

Is 01/04/2020 version 4.6.26011.1.

So I am utterly confused. Microsoft Graph 3.2.0 says it is dependent on .NET Framework 4.6.1 yet it complains about requiring system.net.http 4.2.0.0 and despite having .NET Framework 4.7.2 installed I have all this mess.

I never had issues using Microsoft Graph in the past and it is only because I upgraded to their latest libraries via NuGet Manager that my tool is utterly broken.

I have tried all of the suggestions found on SO about binding redirects and deleting old files. I just don't why Microsoft Graph says it is dependent on 4.6.1 yet the exception said it needed (and couldn't find 4.2.0.0 which is Framework 4.7.2).

I kindly appreciate any specific steps to resolve this issue so that my application will not only compile again but actually work like it used to do.


Solution

  • I stumbled over this question and based on the comments it said that my app.config needed to be:

      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.0.0.0"/>
      </dependentAssembly>
    

    Since the Microsoft Graph package is dependent on .NET Framework 4.6.1 we need to be using the 4.0.0.0 system.net.http else we get the conflict errors.

    Sorted.