-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MissingMethodException: Method not found: System.Net.Http.WinHttpHandler.set_ServerCertificateValidationCallback #28826
Comments
That is causing the mismatch since the 4.0.0 System.Net.Http.dll assembly from . NET Framework doesn't have the required property. @ericstj can you advise on this? Is this a packaging problem? cc: @karelz |
Hi, The 4.2.0 System.Net.Http.dll is copied during build from the following path: If I overwrite it here with the 4.0.0 System.Net.Http.dll from GAC, then everything works fine. It seems System.Net.Http.WinHttpHandler only needs the 4.0.0 version, so it's really strange that the NuGet PackageReference brings the 4.2.0 into the bin folder... Another workaround is an assembly redirect in the executable's app.config:
But as I mentioned in my original post: unfortunately it does not help in my case :( Regards, |
This is basically a duplicate of #24382. |
Most of the workaround suggested do involve using assembly binding redirects in the app.config file. That won't help you as the library author. It would be a step required by consumers of your library that build executables. One thing not mentioned in this issue is the version of Visual Studio being used. The most recent updates to Visual Studio 2017 include some logic in the tools that try to smooth out the problems here and automatically generate the binding redirects to prefer using the inbox (GAC'd) version of System.Net.Http. Have you tried using the latest Visual Studio 2017 updates? |
I've installed the latest Visual Studio update (15.9.10), cleaned the output directories, rebuilt the solution, but it's the same, the MethodNotFoundException is still thrown :( |
Can you please share with us exact steps how to reproduce the problem? (ideally on minimal repro) |
I downloaded the link you posted: WinHttpHandlerPropertyCheck.zip I did not get the exception. I see this in the Output pane of Visual Studio 2017:
|
@gaborposz are you able to reproduce the problem on clean VM? |
One thing I noticed when building the solution:
This message "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2110,5): warning MSB3277: Found conflicts between different versions of "System.Net.Http" that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed." is shown. But when I run the application, it is able to load the GAC'd version of System.Net.Http (as you can see from the output I posted in the earlier comment). I noticed that both of your projects in the solution target .NET Framework 4.7. On my machine, though, I have .NET Framework 4.7.2 actually installed. What version of .NET Framework do you have installed on your machine? Can you run the following C# program and give me the output? It will tell us the specific binaries you are using on your machine. using System;
using System.IO;
using System.Diagnostics;
using System.Net.Http;
using System.Reflection;
public class App
{
public static void Main(string[] args)
{
Console.WriteLine(GetAssemblyVersion(typeof(Uri))); // System.dll
Console.WriteLine();
Console.WriteLine(GetAssemblyVersion(typeof(HttpClient))); // System.Net.Http.dll
}
public static string GetAssemblyVersion(Type t)
{
string path = t.Assembly.Location;
FileVersionInfo fi = FileVersionInfo.GetVersionInfo(path);
string retval = "*************************************************************\r\n";
retval += "Information for: " + Path.GetFileName(path);
retval += "\r\n Location: " + Path.GetDirectoryName(path);
retval += "\r\n CLR Version: " + t.Assembly.ImageRuntimeVersion;
retval += "\r\n File Version: " + fi.FileVersion;
retval += "\r\n Creation Date: " + System.IO.File.GetCreationTime(path);
retval += "\r\n Last Modified: " + System.IO.File.GetLastWriteTime(path);
retval += "\r\n*************************************************************";
return retval;
}
} |
Hello, This was the System.Net.Http.dll's version in the GAC before the install:
And after the install:
As you can see, the File Version is different. I've uploaded the collected logs (before and after) to here: Maybe in the System.Net.Http.WinHttpHandler NuGet package you could correct the .nuspec to use a different System.Net.Http.dll version in case of .NET Framework prior to 4.7.2. But I'm not sure if it is possible... Anyway, .NET Framework 4.7.2 seems to be a possible workaround for us, so thanks a lot for the help! Regards, |
Closing the issue as addressed with 4.7.2. |
I'm using the System.Net.Http.WinHttpHandler 4.5.2 NuGet package from a .NET Framework 4.7 project, and I get the following exception when I use the ServerCertificateValidationCallback property:
System.MissingMethodException: 'Method not found: 'Void System.Net.Http.WinHttpHandler.set_ServerCertificateValidationCallback(System.Func'5<System.Net.Http.HttpRequestMessage,System.Security.Cryptography.X509Certificates.X509Certificate2,System.Security.Cryptography.X509Certificates.X509Chain,System.Net.Security.SslPolicyErrors,Boolean>)'.'
The rest of the package is working well, but due to this error I cannot handle missing or non-trusted certificate errors.
Eventually I was able to create a pretty simple Visual Studio Solution to reproduce the problem:
WinHttpHandlerPropertyCheck.zip
I have two projects in it:
When the executable calls the library, the MissingMethodException is thrown.
I've already learned the following:
The executable links with the 4.0.0 System.Net.Http assembly that is available in GAC (since it is coming from the .NET Framework), while the library links with the 4.2.0 System.Net.Http assembly (because
the WinHttpHandler package is explicitly referencing that version). Both dlls are loaded into the running executable, but when the CLR tries to JIT the library's method the parameter types in the ServerCertificateValidationCallback mismatch with the already loaded types, and the exception is thrown.
Any idea how to solve it?
My library is supposed to be used by various executables, so application specific solutions (e.g. app.config changes) are not working for me.
Thank you in advance,
Gabor
The text was updated successfully, but these errors were encountered: