first chance exception of type 'System.Security.Authentication.AuthenticationException'

Nov 14, 2012 at 9:18 PM

I'm attempting to connect to an FTP server using an Implicit connection but I'm getting an error: "A first chance exception of type 'System.Security.Authentication.AuthenticationException' occurred in System.dll"

Code:

using (FtpClient conn = new FtpClient()) {
      conn.Host = "localhost";
      conn.Port = 990;
      conn.Credentials = new NetworkCredential("test", "test1");
      conn.EncryptionMode = FtpEncryptionMode.Implicit;
                              
      conn.Connect();
}

 

Error:

Step into: Stepping over method without symbols 'System.Threading.Mutex.Mutex'
Step into: Stepping over method without symbols 'System.Collections.Generic.Dictionary.Dictionary'
Step into: Stepping over method without symbols 'System.Text.Encoding.ASCII.get'
'Examples.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.Host.set'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.Port.set'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over method without symbols 'System.Net.NetworkCredential.NetworkCredential'
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.Credentials.set'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.EncryptionMode.set'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over method without symbols 'System.Threading.WaitHandle.WaitOne'
Step into: Stepping over method without symbols 'System.IO.Stream.Stream'
Step into: Stepping over method without symbols 'System.MulticastDelegate.CtorClosed'
Step into: Stepping over method without symbols 'System.Net.FtpClient.FtpSocketStream.m_sslvalidate.add'
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.Host.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.Credentials.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over method without symbols 'System.Text.Encoding.Default.get'
Step into: Stepping over property 'System.Net.FtpClient.FtpSocketStream.ConnectTimeout.set'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.Host.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.Port.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over method without symbols 'System.Net.Dns.GetHostAddresses'
Step into: Stepping over method without symbols 'System.Net.IPAddress.AddressFamily.get'
Step into: Stepping over method without symbols 'System.Net.Sockets.Socket.Socket'
Step into: Stepping over method without symbols 'System.Net.Sockets.Socket.BeginConnect'
Step into: Stepping over method without symbols 'System.Net.LazyAsyncResult.AsyncWaitHandle.get'
Step into: Stepping over method without symbols 'System.Threading.WaitHandle.WaitOne'
Step into: Stepping over method without symbols 'System.Net.Sockets.Socket.EndConnect'
Step into: Stepping over method without symbols 'System.Net.Sockets.Socket.Connected.get'
Step into: Stepping over method without symbols 'System.Net.Sockets.NetworkStream.NetworkStream'
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.EncryptionMode.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.Host.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over property 'System.Net.FtpClient.FtpSocketStream.IsConnected.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over property 'System.Net.FtpClient.FtpSocketStream.NetworkStream.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over method without symbols 'System.MulticastDelegate.CtorClosed'
Step into: Stepping over method without symbols 'System.Net.Security.SslStream.SslStream'
Step into: Stepping over method without symbols 'System.Net.Security.SslStream.AuthenticateAsClient'
A first chance exception of type 'System.Security.Authentication.AuthenticationException' occurred in System.dll
A first chance exception of type 'System.Security.Authentication.AuthenticationException' occurred in System.dll
Step into: Stepping over method without symbols 'System.Diagnostics.Debug.WriteLine'
System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
   at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
   at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost)
   at System.Net.FtpClient.FtpSocketStream.ActivateEncryption(String targethost) in c:\Users\MDeitrick\Downloads\netftp-acac39e9b559\netftp_acac39e9b559\System.Net.FtpClient\FtpSocketStream.cs:line 501
Step into: Stepping over method without symbols 'System.Net.Sockets.Socket.Connected.get'
Step into: Stepping over method without symbols 'System.Net.Sockets.Socket.Close'
Step into: Stepping over method without symbols 'System.Net.Sockets.Socket.Dispose'
Step into: Stepping over method without symbols 'System.IO.Stream.Dispose'
Step into: Stepping over method without symbols 'System.IO.Stream.Dispose'
A first chance exception of type 'System.Security.Authentication.AuthenticationException' occurred in System.Net.FtpClient.dll
Step into: Stepping over method without symbols 'System.Threading.Mutex.ReleaseMutex'
Step into: Stepping over property 'System.Net.FtpClient.FtpSocketStream.IsConnected.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over method without symbols 'System.IO.Stream.Dispose'
Step into: Stepping over method without symbols 'System.Exception.ToString'
Step into: Stepping over method without symbols 'System.IO.TextWriter.SyncTextWriter.WriteLine'
Step into: Stepping over method without symbols 'System.Console.ReadKey'
The program '[3620] Examples.exe: Managed (v4.0.30319)' has exited with code -1 (0xffffffff).

Coordinator
Nov 14, 2012 at 9:39 PM
You need to handle the validatecertificate event, the event args contain what you need to validate and continue.

Sent from my iPhone

On Nov 14, 2012, at 4:18 PM, lickfrog <notifications@codeplex.com> wrote:

From: lickfrog

I'm attempting to connect to an FTP server using an Implicit connection but I'm getting an error: "A first chance exception of type 'System.Security.Authentication.AuthenticationException' occurred in System.dll"

Code:

using (FtpClient conn = new FtpClient()) {
      conn.Host = "localhost";
      conn.Port = 990;
      conn.Credentials = new NetworkCredential("test", "test1");
      conn.EncryptionMode = FtpEncryptionMode.Implicit;
                              
      conn.Connect();
}

Error:

Step into: Stepping over method without symbols 'System.Threading.Mutex.Mutex'
Step into: Stepping over method without symbols 'System.Collections.Generic.Dictionary.Dictionary'
Step into: Stepping over method without symbols 'System.Text.Encoding.ASCII.get'
'Examples.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.Host.set'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.Port.set'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over method without symbols 'System.Net.NetworkCredential.NetworkCredential'
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.Credentials.set'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.EncryptionMode.set'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over method without symbols 'System.Threading.WaitHandle.WaitOne'
Step into: Stepping over method without symbols 'System.IO.Stream.Stream'
Step into: Stepping over method without symbols 'System.MulticastDelegate.CtorClosed'
Step into: Stepping over method without symbols 'System.Net.FtpClient.FtpSocketStream.m_sslvalidate.add'
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.Host.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.Credentials.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over method without symbols 'System.Text.Encoding.Default.get'
Step into: Stepping over property 'System.Net.FtpClient.FtpSocketStream.ConnectTimeout.set'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.Host.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.Port.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over method without symbols 'System.Net.Dns.GetHostAddresses'
Step into: Stepping over method without symbols 'System.Net.IPAddress.AddressFamily.get'
Step into: Stepping over method without symbols 'System.Net.Sockets.Socket.Socket'
Step into: Stepping over method without symbols 'System.Net.Sockets.Socket.BeginConnect'
Step into: Stepping over method without symbols 'System.Net.LazyAsyncResult.AsyncWaitHandle.get'
Step into: Stepping over method without symbols 'System.Threading.WaitHandle.WaitOne'
Step into: Stepping over method without symbols 'System.Net.Sockets.Socket.EndConnect'
Step into: Stepping over method without symbols 'System.Net.Sockets.Socket.Connected.get'
Step into: Stepping over method without symbols 'System.Net.Sockets.NetworkStream.NetworkStream'
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.EncryptionMode.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.Host.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over property 'System.Net.FtpClient.FtpSocketStream.IsConnected.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over property 'System.Net.FtpClient.FtpSocketStream.NetworkStream.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over method without symbols 'System.MulticastDelegate.CtorClosed'
Step into: Stepping over method without symbols 'System.Net.Security.SslStream.SslStream'
Step into: Stepping over method without symbols 'System.Net.Security.SslStream.AuthenticateAsClient'
A first chance exception of type 'System.Security.Authentication.AuthenticationException' occurred in System.dll
A first chance exception of type 'System.Security.Authentication.AuthenticationException' occurred in System.dll
Step into: Stepping over method without symbols 'System.Diagnostics.Debug.WriteLine'
System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
   at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
   at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost)
   at System.Net.FtpClient.FtpSocketStream.ActivateEncryption(String targethost) in c:\Users\MDeitrick\Downloads\netftp-acac39e9b559\netftp_acac39e9b559\System.Net.FtpClient\FtpSocketStream.cs:line 501
Step into: Stepping over method without symbols 'System.Net.Sockets.Socket.Connected.get'
Step into: Stepping over method without symbols 'System.Net.Sockets.Socket.Close'
Step into: Stepping over method without symbols 'System.Net.Sockets.Socket.Dispose'
Step into: Stepping over method without symbols 'System.IO.Stream.Dispose'
Step into: Stepping over method without symbols 'System.IO.Stream.Dispose'
A first chance exception of type 'System.Security.Authentication.AuthenticationException' occurred in System.Net.FtpClient.dll
Step into: Stepping over method without symbols 'System.Threading.Mutex.ReleaseMutex'
Step into: Stepping over property 'System.Net.FtpClient.FtpSocketStream.IsConnected.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over method without symbols 'System.IO.Stream.Dispose'
Step into: Stepping over method without symbols 'System.Exception.ToString'
Step into: Stepping over method without symbols 'System.IO.TextWriter.SyncTextWriter.WriteLine'
Step into: Stepping over method without symbols 'System.Console.ReadKey'
The program '[3620] Examples.exe: Managed (v4.0.30319)' has exited with code -1 (0xffffffff).

Nov 15, 2012 at 12:15 PM

Modified code as Follows:

public static void ValidateCertificate() {
      using (FtpClient conn = new FtpClient()) {
            conn.Host = "localhost";
            conn.Port = 990;
            conn.Credentials = new NetworkCredential("test", "test1");
            conn.EncryptionMode = FtpEncryptionMode.Implicit;                
            conn.ValidateCertificate += new FtpSslValidation(OnValidateCertificate);
            conn.Connect();
      }
}

static void OnValidateCertificate(FtpClient control, FtpSslValidationEventArgs e) {
      if (e.PolicyErrors != System.Net.Security.SslPolicyErrors.None) {
            // invalid cert, do you want to accept it?
            e.Accept = true;
      }
}

Getting the following output:

Step into: Stepping over method without symbols 'System.Threading.Mutex.Mutex'
Step into: Stepping over method without symbols 'System.Collections.Generic.Dictionary.Dictionary'
Step into: Stepping over method without symbols 'System.Text.Encoding.ASCII.get'
'Examples.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.Host.set'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.Port.set'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over method without symbols 'System.Net.NetworkCredential.NetworkCredential'
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.Credentials.set'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.EncryptionMode.set'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over method without symbols 'System.MulticastDelegate.CtorOpened'
Step into: Stepping over method without symbols 'System.Delegate.Combine'
Step into: Stepping over method without symbols 'System.Threading.WaitHandle.WaitOne'
Step into: Stepping over method without symbols 'System.IO.Stream.Stream'
Step into: Stepping over method without symbols 'System.MulticastDelegate.CtorClosed'
Step into: Stepping over method without symbols 'System.Net.FtpClient.FtpSocketStream.m_sslvalidate.add'
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.Host.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.Credentials.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over method without symbols 'System.Text.Encoding.Default.get'
Step into: Stepping over property 'System.Net.FtpClient.FtpSocketStream.ConnectTimeout.set'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.Host.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.Port.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over method without symbols 'System.Net.Dns.GetHostAddresses'
Step into: Stepping over method without symbols 'System.Net.IPAddress.AddressFamily.get'
Step into: Stepping over method without symbols 'System.Net.Sockets.Socket.Socket'
Step into: Stepping over method without symbols 'System.Net.Sockets.Socket.BeginConnect'
Step into: Stepping over method without symbols 'System.Net.LazyAsyncResult.AsyncWaitHandle.get'
Step into: Stepping over method without symbols 'System.Threading.WaitHandle.WaitOne'
Step into: Stepping over method without symbols 'System.Net.Sockets.Socket.EndConnect'
Step into: Stepping over method without symbols 'System.Net.Sockets.Socket.Connected.get'
Step into: Stepping over method without symbols 'System.Net.Sockets.NetworkStream.NetworkStream'
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.EncryptionMode.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over property 'System.Net.FtpClient.FtpClient.Host.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over property 'System.Net.FtpClient.FtpSocketStream.IsConnected.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over property 'System.Net.FtpClient.FtpSocketStream.NetworkStream.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over method without symbols 'System.MulticastDelegate.CtorClosed'
Step into: Stepping over method without symbols 'System.Net.Security.SslStream.SslStream'
Step into: Stepping over method without symbols 'System.Net.Security.SslStream.AuthenticateAsClient'
A first chance exception of type 'System.Security.Authentication.AuthenticationException' occurred in System.dll
A first chance exception of type 'System.Security.Authentication.AuthenticationException' occurred in System.dll
Step into: Stepping over method without symbols 'System.Diagnostics.Debug.WriteLine'
System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
   at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
   at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost)
   at System.Net.FtpClient.FtpSocketStream.ActivateEncryption(String targethost) in c:\Users\MDeitrick\Downloads\netftp-acac39e9b559\netftp_acac39e9b559\System.Net.FtpClient\FtpSocketStream.cs:line 501
Step into: Stepping over method without symbols 'System.Net.Sockets.Socket.Connected.get'
Step into: Stepping over method without symbols 'System.Net.Sockets.Socket.Close'
A first chance exception of type 'System.Security.Authentication.AuthenticationException' occurred in System.Net.FtpClient.dll
The program '[9616] Examples.exe: Managed (v4.0.30319)' has exited with code -1 (0xffffffff).

Coordinator
Nov 15, 2012 at 12:58 PM

You have to accept the certificate regardless if has validation errors or not, if you want to continue. Your event handler should set the e.Accept property to true if it wants to accept the certificate. How you handle validation errors is up to you. You may want to log them, you may want to abort the connection, etc. but if you want to continue, event when a certificate is valid, you need to set e.Accept = true;

 

Nov 15, 2012 at 1:50 PM

Doesn't the above example (modified code) not set the e.Accept property equal to true? Can you provide a simple example of what this would look like?

Nov 15, 2012 at 2:09 PM

Debugging indicates that the issue may be in FtpSocketStream.cs under the ActivateEncryption object on line 493 it throws a new InvalidOperationException("SSL Encryption has already been enabled on this stream.");

Coordinator
Nov 15, 2012 at 7:00 PM

This is what I meant:

static void OnValidateCertificate(FtpClient control, FtpSslValidationEventArgs e) {
      e.Accept = true;
}
As far as the exception you mentioned above goes, I'm not able to reproduce this behavior. If this indeed the problem I need to know what server software you are connecting to (exact version) and the OS it's running on. Also are you testing with Microsoft's .NET implementation or mono? The runtime can affect things like this as well.

Coordinator
Nov 29, 2012 at 2:42 PM

I've updated the code in regards to this issue. You should not have set e.Accept = true even when there are no policy errors. The new changes reflect this logic, e.Accept will already be true SslPolicyErrors == PolicyErrors.None.