Flurl: 4.6.1 class library unit test "MissingMethodException"
To recreate:
- Create a new .NetStandard library with a method using Flurl (EDIT: Not necessary, skip to step 2).
- Create a class library targeting 4.6.1
- 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": {}
}
}
- Reload project
- 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)
@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.
I had to add::
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:
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