This project is read-only.


NullReferenceException in Renci.SshNet.BaseClient.IsConnected()



while using Renci SSH Client successfully in production, I noticed a really rare error that just occurred on my dev machine:
4491 - OXE Control Center Gui: 15:08:15.9481613 - [Remote Connector] Detected stop flag, terminating remote connection...
2482 - OXE Control Center Gui: 15:08:16.0824215 - [Remote Connector] Error on connection check!

Source: Renci.SshNet

System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
   bei Renci.SshNet.Session.IsSocketConnected(Boolean& isConnected)
   bei Renci.SshNet.Session.get_IsConnected()
   bei Renci.SshNet.BaseClient.get_IsConnected()
   bei NextiraOne.Processors.RemoteConnector.IsConnected() in C:\Users\nsk\Documents\Visual Studio 2010\Projects\9 - NextiraOne Libraries\NextiraOne.Core\SP_RemoteConnector.cs:Zeile 393.
Notice my generic log message prefixes from my wrapper class around Renci.SshNet that tells us what happened here and in what short timeframe this occurs:
My program execution was stopped due to the internal stop flag and immediately after that the connection state was checked (don't think about the use case as I have a complicated multithreaded environment in which this check may be optimized/blocked at this stop situation, but this is a different topic :D )

The excpected result from IsConnected() is false here.

This is not severe, as my connection check treats errors equal to false. But just to improve Renci.SshNet I post this case here. :)

"Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt." means in english kind of "The object reference does not point to an object".

Closed Jan 28, 2013 at 5:41 PM by olegkap


nsk7even wrote Jan 28, 2013 at 2:36 PM

This error occurred with SVN revision 22445

olegkap wrote Jan 28, 2013 at 3:20 PM


Thanks for letting me know.
Do you mind update to latest version and see how it works now?
Also, what version do you use? 4.0, 3.5, Silverlight etc?
The reason I ask is because this method is partial and implemented differently in each environment.


nsk7even wrote Jan 28, 2013 at 4:25 PM

Hi Oleg,

I just compiled revision 22733 and let my application run with this one for a while...
But I doubt to get the error again since I never saw it before (and I am actively developing at other parts of my application which always needs the ssh connection).

What I wanna say is that I assume the timeframe is really short in which I have to call the connected state after sending the disconnect command to provoke the above exception.

My platform is .NET 4.0 on an x64 machine, using AnyCPU profile in debug mode.

I just checked my lab system where my app is installed as windows service in release mode and there the above error never occurred. I am sorry to not being able to check the production system as I have to request the access for it with reason...


olegkap wrote Jan 28, 2013 at 5:41 PM


Thanks for looking into it.
From what I see the only reason why this error can occur in IsConnectioned method is because while testing the connection socket was closed and disposed.
If this error occurs again and you can get it somewhat consistent you can try update IsConnected method as follow:
        partial void IsSocketConnected(ref bool isConnected)
            if (this._socket != null)
                lock (this._socketLock)
                    isConnected = (!this._isDisconnecting && this._socket != null && this._socket.Connected && this._isAuthenticated && this._messageListenerCompleted != null)
                        && this._socket.Poll(-1, SelectMode.SelectWrite);
                isConnected = false;
And let me know if it solves it.
I will go ahead then and close this issue but will keep it in mind in case someone else reports it again or if it happens more often.


wrote Jan 28, 2013 at 5:41 PM

wrote Feb 22, 2013 at 2:17 AM

wrote May 16, 2013 at 1:14 PM