I’m trying to use the new System.Net.Http bits to build a simple HTTP client to talk to an HTTP-based API. I installed the bits with Nuget (Microsoft.AspNet.WebApi.Client.4.0.20505.0).
I need to accept some self-signed certificates, so I’m trying to set the ServerCertificateValidationCallback property of the WebRequestHandler class. Here’s a two line test illustrating the problem I’m encountering:
[Test]
public void CanRunDummyTest() {
var handler = new WebRequestHandler();
handler.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;
}
but it throws:
CanRunDummyTest : FailedSystem.MissingMethodException :
Method not found: 'Void System.Net.Http.WebRequestHandler.set_ServerCertificateValidationCallback(System.Net.Security.RemoteCertificateValidationCallback)'
at AxlTests.RawAxlTests.CanRunDummyTest()
It seems that the Set property of the class is not implemented? Any ideas?
MissingMethodException‘s generally happen when compiling and executing against the same type which has undergone a breaking ABI change (forwards or backwards) .... and I expect that is what is happening here.
Accoding to WebRequestHandler.ServerCertificateValidationCallback Property, that property is only “supported in .NET 4.5”, so using the .NET 4.0 version will go kaboom!
When building, be sure that .NET 4.0 (or applicable) is the target to (hopefully) get compile-time errors.