Exception while disposing sshclient object

Dec 9, 2014 at 8:27 AM
Edited Dec 9, 2014 at 8:28 AM
Hello all

I am using the SSH.Net library in a project where I connect to a NetApp host. This generally works very good. However in cases where the host does not answer I get the following exception:
A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied System.Net.Sockets.SocketException (0x80004005): A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied
   at System.Net.Sockets.Socket.Disconnect(Boolean reuseSocket)
   at Renci.SshNet.Session.SocketDisconnectAndDispose()
   at Renci.SshNet.Session.Disconnect(DisconnectReason reason, String message)
   at Renci.SshNet.Session.Dispose(Boolean disposing)
   at Renci.SshNet.BaseClient.Dispose(Boolean disposing)
   at Renci.SshNet.SshClient.Dispose(Boolean disposing)
   at Renci.SshNet.BaseClient.Dispose()
The code snipped I am using. The exception happens on the SshClientObject.Dispose(). Before I check if the object is still connected and then disconnect if needed. But I do not understand whe there is an exception while disposing the object.
if (!done) {
    if (SshClientObject != null) {
        SshClientObject.KeepAliveInterval = new TimeSpan(0, 0, 0, 0, -1);
        if (SshClientObject.IsConnected) {
            SshClientObject.Disconnect();
        }
        SshClientObject.Dispose();            <------ Exception here ....
        SshClientObject = null;
    }
    return false;
}
I am currently using the beta 1 version.

Any idea?
Philipp
Coordinator
Dec 9, 2014 at 10:58 AM
Philipp,
What version of SSH.NET are you using ?
Dec 9, 2014 at 1:01 PM
Edited Dec 9, 2014 at 1:09 PM
As I wrote: 2014.4.6-beta1. This is a productive system and it is not that easy to deploy the lates version.

In the code I saw that SshClientobject.Dispose() also calles the Disconnect() methode. The exception I have is actually comming from the Disconnect() method. Why does this method not see that the connection is already disconnected?

Or better asked: How to correctly disconnect and dispose this object without exception?

Philipp