Throw System.MissingMethodException when call ToHttpClient
Ducatel opened this issue · 5 comments
Hi,
I have an exception throw when I try to call MockHttpMessageHandler::ToHttpClient
.
So my code is very simple, and a really don't understand where this problem come from.
Do you have any idea about that ?
Thanks in advance pour your help ;)
The Exception:
System.MissingMethodException: Method not found : 'System.Net.Http.HttpClient RichardSzalay.MockHttp.MockHttpMessageHandler.ToHttpClient()'.
The code which produce the exception
using RichardSzalay.MockHttp;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace AllTest
{
[TestClass]
public class MyClassTest
{
[TestMethod]
public void TestMethod1()
{
(new MockHttpMessageHandler()).ToHttpClient();
}
}
}
Version info:
- Target:
Net4.6.1
- Visual Studio
15.7.4
- .Net Framework:
4.7.02558
package.config
<packages>
<package id="Castle.Core" version="4.3.1" targetFramework="net461" />
<package id="Moq" version="4.8.3" targetFramework="net461" />
<package id="MSTest.TestAdapter" version="1.3.2" targetFramework="net461" />
<package id="MSTest.TestFramework" version="1.3.2" targetFramework="net461" />
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net461" />
<package id="RichardSzalay.MockHttp" version="5.0.0" targetFramework="net461" />
<package id="SimpleInjector" version="4.3.0" targetFramework="net461" />
<package id="System.IO.Abstractions" version="2.1.0.199" targetFramework="net461" />
<package id="System.IO.Abstractions.TestingHelpers" version="2.1.0.199" targetFramework="net461" />
<package id="System.Net.Http" version="4.3.3" targetFramework="net461" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.1" targetFramework="net461" />
<package id="System.Security.Cryptography.Algorithms" version="4.3.1" targetFramework="net461" />
<package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net461" />
<package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net461" />
<package id="System.Security.Cryptography.X509Certificates" version="4.3.2" targetFramework="net461" />
<package id="System.Threading.Tasks.Extensions" version="4.5.1" targetFramework="net461" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net461" />
</packages>
First up, thanks for taking the time to write up such a detailed issue!
As part of the 5.0 release, MockHttp realigned it's references with the official recommendations (outlined here).
Can you try removing the System.Net.Http page from your project and instead referencing the built in (GAC) version of System.Net.Http?
Hi, no problem for the issue, you take time to publish good libs on opensource. So I can take a little of my time for creating a proper issue ;)
So dropping ref on System.Net.Http
didn't solve the problem.
But, I found the problem and it not come from your lib
To fix that issue, I just need to downgrade System.Threading.Tasks.Extensions
to version 4.3.0
or adding that configuration to my csproj
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
If you want to investigate by yourself:
Thanks and have fun ;)
Glad you managed to fix it, and thanks for detailing how you solved it!