Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NetConfClient SendReceiveRpc with AutomaticMessageIdHandling can cause NullReferenceException #3

Open
tloader11 opened this issue Apr 29, 2021 · 1 comment

Comments

@tloader11
Copy link

Renci.SshNet/Netconf/NetConfSession.cs -> _messageId is undefined when calling SendReceiveRpc.

The following code:

            var netConfClient = new NetConfClient("hostname.here", 830, "usernamehere", "passwordhere");
            
            netConfClient.Connect();

            if (netConfClient.IsConnected)
            {
                XmlDocument rpc = new XmlDocument();
                rpc.LoadXml("<rpc><get-interface-information></get-interface-information></rpc>");

                var rpcResponse = netConfClient.SendReceiveRpc(rpc);

                Console.Write(rpcResponse.OuterXml);
            }

This causes the following issue:

Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at Renci.SshNet.NetConf.NetConfSession.SendReceiveRpc(XmlDocument rpc, Boolean automaticMessageIdHandling)
   at Renci.SshNet.NetConfClient.SendReceiveRpc(XmlDocument rpc)

Currently using

AutomaticMessageIdHandling = false

to bypass this issue.

Proposed fix is init'ing the _messageId in the constructor.

@MagnusArias
Copy link

I found the error in source code:

rpc.SelectSingleNode("/nc:rpc/@message-id", nsMgr).Value = _messageId.ToString(CultureInfo.InvariantCulture);

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants