title: How to use certificate callback in SslStream.AuthenticateAsClient method?
body: <p>My C#.NET SSL connect works when I import the certificate manually in IE (Tools/Internet Options/Content/Certificates), but how can I load the certificate by code?
  Here is my code:</p>
  
  <pre><code>TcpClient client = new TcpClient(ConfigManager.SSLSwitchIP, Convert.ToInt32(ConfigManager.SSLSwitchPort));
  
  SslStream sslStream = new SslStream(
                  client.GetStream(),
                  false,
                  new RemoteCertificateValidationCallback(ValidateServerCertificate),
                  null
                  );
  sslStream.AuthenticateAsClient("Test");
  </code></pre>
  
  <p>The above code works fine if i import my certificate file manually in Internet Explorer. But if i remove my certificate from IE and use the following code instead, i get Authentication exception:</p>
  
  <pre><code>sslStream.AuthenticateAsClient("Test", GetX509CertificateCollection(), SslProtocols.Default, false);
  </code></pre>
  
  <p>and here is the 'GetX509CertificateCollection' method :</p>
  
  <pre><code>public static X509CertificateCollection GetX509CertificateCollection()
          {
              X509Certificate2 certificate1 = new X509Certificate2("c:\\ssl.txt");
              X509CertificateCollection collection1 = new X509CertificateCollection();
              collection1.Add(certificate1);
              return collection1;
          }
  </code></pre>
  
  <p>What should I do to load my certificate dynamically?</p>