title: Why is my ServicePointManager.ServerCertificateValidationCallback being ignored?
body: <p>I'm making a web request in a winforms app. I'm providing custom certificate validation like so:</p>
  
  <pre><code>    ServicePointManager.ServerCertificateValidationCallback += 
          new RemoteCertificateValidationCallback(certValidator.ValidateRemoteCertificate);
  </code></pre>
  
  <p>where certValidator.ValidateRemoteCertificate is</p>
  
  <pre><code>public bool ValidateRemoteCertificate(object sender, X509Certificate certificate,
                                        X509Chain chain, SslPolicyErrors policyErrors)
  {
          return false;
  }
  </code></pre>
  
  <p>As you can see, this callback should reject all server certificates and close any attempted connections.</p>
  
  <p>My problem is that this callback is completely ignored. I submit an https request and it works like a charm. Watching it in the debugger I can see that <code>ValidateRemoteCertificate</code> is never invoked.</p>
  
  <p>Why is my replacement callback never called back?</p>
  
  <p>EDIT: LB asked for the webrequest, so here it is:</p>
  
  <pre><code>HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sourceUrl);
  request.UseDefaultCredentials = true;
  request.UserAgent = "Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US))";    
  
  request.KeepAlive = false;
  request.Headers.Add("Accept-Language", "en-us,en;q=1.0");
  request.Method = "GET";
  HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  </code></pre>
  
  <p>EDIT 2: It's probably unrelated, but in the .config file I instruct it to use the configured proxy like so:</p>
  
  <pre><code>&lt;system.net&gt;
      &lt;defaultProxy useDefaultCredentials="true"/&gt;
  &lt;/system.net&gt;
  </code></pre>
  
  <p>EDIT 3: Below is a complete, minimal example that manifests the behavior. I expect this example to throw an exception because all certificates should be rejected, but it works just fine.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Net;
  using System.Text;
  
  namespace SPMCertCallbackDemonstrator
  {
      class Program
      {
          static void Main(string[] args)
          {
              ServicePointManager.ServerCertificateValidationCallback = delegate { return false;};
              HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com");
              request.Method = "GET";
              HttpWebResponse response = (HttpWebResponse)request.GetResponse();
          }
      }
  }
  </code></pre>
  
  <p>Why is my replacement callback never called back?</p>