NullReferenceException in SshSession.IsConnected

+1 vote
asked Apr 22, 2015 by moski (210 points)

There is a NullReferenceException when you check SshSession.IsConnected property before you call a Connect method for the first time.

        try {
            SshSession session = new SshSession();
            Console.WriteLine("IsConnected: {0}", session.IsConnected);
        catch (NullReferenceException ex) {
            Console.WriteLine("Found a BUG!");

1 Answer

0 votes
answered Apr 22, 2015 by Lukas Pokorny (124,610 points)
edited Aug 19, 2015 by Tomas Knopp
Best answer


The fix has now been released as part of version 2015R4 of Rebex components.

This is indeed a bug - thanks for bringing it to our attention!

We will fix this in the next release. In the meantime, please use the following workaround:

SshSession session = new SshSession();
bool isConnected = (session.Socket != null) ? session.IsConnected : false;
Console.WriteLine("IsConnected: {0}", isConnected);