SSH.NET icon indicating copy to clipboard operation
SSH.NET copied to clipboard

NetConfClient.SendReceiveRpc(xml) - System.NullReferenceException

Open shef opened this issue 6 years ago • 2 comments

I'm learning SSH.NET and stuck at SendReceiveRpc. Every time I try to send any command - I'm getting NullReferenceException.

The code is very simple, probably I'm doing something stupid:

var ncClient = new NetConfClient(remoteHost, 22, user, password);
ncClient.Connect();

string getSoftwareVersion = @"<get-software-information/>";
XmlDocument software;

software = ncClient.SendReceiveRpc(getSoftwareVersion);

On last line I'm getting NullReferenceException. In the locals I see that ncClient.IsConnected = true. Any suggestions? RTFM? Using SSH.NET version 2016.1.0 package.

shef avatar May 03 '20 04:05 shef

I found the error in source code: https://github.com/sshnet/SSH.NET/blob/develop/src/Renci.SshNet/Netconf/NetConfSession.cs#L62

Line 62, inappropriate usage of "_messageID" variable. This variable never had value assigned. Alternatively, you can set "automaticMessageIdHandling" to "false" and it works then

MagnusArias avatar Jul 06 '23 09:07 MagnusArias

Hi With similar code I get timeout from teh device:

var ncClient = new NetConfClient(remoteHost, 22, user, password);
ncClient.Connect();
Console.WriteLine("Connected")

The error I get is following:

Unhandled exception. Renci.SshNet.Common.SshException: Channel was closed.
at Renci.SshNet.SubsystemSession.WaitOnHandle(WaitHandle waitHandle, Int32 millisecondsTimeout)
at Renci.SshNet.NetConf.NetConfSession.OnChannelOpen()
at Renci.SshNet.SubsystemSession.Connect()
at Renci.SshNet.NetConfClient.CreateAndConnectNetConfSession()
at Renci.SshNet.NetConfClient.OnConnected()
at Renci.SshNet.BaseClient.Connect()
at Program.<Main>$(String[] args) in /home/mssy/Program.cs:line 12

Credentials correct, but I cannot understand why I get timeout. Debug on the router doesn't provide any useful info

pyrius avatar Oct 23 '23 17:10 pyrius