Home > Enterprise >  'HttpClientHandler' does not contain a definition for 'ServerCertificateValidationCal
'HttpClientHandler' does not contain a definition for 'ServerCertificateValidationCal

Time:05-11

I am currently in the process of migrating a huge solution from .Net Framework 4.7.2 to .Net Core 3.1. In the current Project (which now targets .Net Standard 2.0) we had the following code (already changed from WebRequestHandler):

        var handler = new HttpClientHandler
        {
            Proxy = proxy,
            UseDefaultCredentials = useDefaultCredentials,
        };

        if (Configuration.TrustCertificate)
        {
            handler.ServerCertificateValidationCallback = delegate
            {
                return true;
            };
        }

After the migration to .Net Standard 2.0 I get the following build error:

CS1061 'HttpClientHandler' does not contain a definition for 'ServerCertificateValidationCallback' and no accessible extension method 'ServerCertificateValidationCallback' accepting a first argument of type 'HttpClientHandler' could be found (are you missing a using directive or an assembly reference?)

I have referenced the nuget package System.Net.Http (v4.3.4). When I view the definition I see that the ServerCertificateValidationCallback is there but marked as [EditorBrowsable(EditorBrowsableState.Never)] The header of the file is also suspicious:

#region Assembly netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
// C:\Users\myuser\.nuget\packages\netstandard.library\2.0.3\build\netstandard2.0\ref\netstandard.dll
#endregion

I would have expected that the class was in the System.Net.Http package.

Any ideas?

CodePudding user response:

The name of the property is ServerCertificateCustomValidationCallback. If you change the property name, the build error should be fixed.

  • Related