sshnet / SSH.NET

SSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism.
http://sshnet.github.io/SSH.NET/
MIT License
4.02k stars 934 forks source link

NetConfClient.SendReceiveRpc(xml) - System.NullReferenceException #674

Open shef opened 4 years ago

shef commented 4 years ago

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.

MagnusArias commented 1 year ago

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

pyrius commented 1 year ago

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