Flurl: 4.6.1 class library unit test "MissingMethodException"

To recreate:

  1. Create a new .NetStandard library with a method using Flurl (EDIT: Not necessary, skip to step 2).
  2. Create a class library targeting 4.6.1
  3. Create project.json with the following
{
  "dependencies": {
    "FluentAssertions": "4.17.0",
    "Flurl": "2.2.1",
    "Flurl.Http": "1.1.1",
    "NSubstitute": "1.10.0",
    "xunit": "2.1.0"
  },
  "frameworks": {
    "net461": {}
  },
  "runtimes": {
    "win": {}
  }
}
  1. Reload project
  2. Try to run the following
[Fact]
public void Test()
{
    using (var x = new HttpTest())
    {
        "G".GetJsonAsync();
    }
}

Exception :

System.MissingMethodException Method not found: ‘System.Threading.Tasks.Task`1<System.Object> Flurl.Http.HttpExtensions.GetJsonAsync(System.String, System.Threading.CancellationToken, System.Net.Http.HttpCompletionOption)’. at Tests.Class1.Test()

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 2
  • Comments: 24 (4 by maintainers)

Most upvoted comments

@A9G-Data-Droid I suspect it’s the latter. This is a very old issue but to my recollection it was never a problem with (nor fixable by) Flurl, which is just a wrapper around the HttpClient stack.

I ran into basically the same exception after deploying to the cloud for an MVC project with target framework .NET 4.7.1.

Method not found: 'System.Threading.Tasks.Task'1<System.Net.Http.HttpResponseMessage> Flurl.Http.GeneratedExtensions.GetStringAsync(Flurl.Http.IFlurlRequest, System.Object,
System.Threading.CancellationToken, System.Net.Http.HttpCompletionOption)'.

I had to add::

<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>

I was able to work around this by targeting multiple frameworks in such a way that my powershell module loads the full-framework version of my library.

@tmenier Effectively the issue is related to the lack of Binding Redirects for System.Net.Http

I added the following to fake.exe.config and it worked:

<dependentAssembly>
  <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>

I believe that 5.2.3.0 is the version of the assembly used by .NET 4.6, whereas 4.5 had an older version, which might explain why @nlowe 's case worked correctly under NET45