diff --git a/CryptoExchange.Net/Sockets/MessageParsing/JsonNetMessageData.cs b/CryptoExchange.Net/Sockets/MessageParsing/JsonNetMessageData.cs index e3606d7b..93e4c939 100644 --- a/CryptoExchange.Net/Sockets/MessageParsing/JsonNetMessageData.cs +++ b/CryptoExchange.Net/Sockets/MessageParsing/JsonNetMessageData.cs @@ -63,6 +63,9 @@ public object Deserialize(Type type, MessagePath? path = null) /// public NodeType? GetNodeType() { + if (!IsJson) + throw new InvalidOperationException("Can't access json data on non-json message"); + if (_token == null) return null; @@ -78,6 +81,9 @@ public object Deserialize(Type type, MessagePath? path = null) /// public NodeType? GetNodeType(MessagePath path) { + if (!IsJson) + throw new InvalidOperationException("Can't access json data on non-json message"); + var node = GetPathNode(path); if (node == null) return null; @@ -94,6 +100,9 @@ public object Deserialize(Type type, MessagePath? path = null) /// public T? GetValue(MessagePath path) { + if (!IsJson) + throw new InvalidOperationException("Can't access json data on non-json message"); + var value = GetPathNode(path); if (value == null) return default; @@ -107,6 +116,9 @@ public object Deserialize(Type type, MessagePath? path = null) /// public List? GetValues(MessagePath path) { + if (!IsJson) + throw new InvalidOperationException("Can't access json data on non-json message"); + var value = GetPathNode(path); if (value == null) return default; @@ -119,6 +131,9 @@ public object Deserialize(Type type, MessagePath? path = null) private JToken? GetPathNode(MessagePath path) { + if (!IsJson) + throw new InvalidOperationException("Can't access json data on non-json message"); + var currentToken = _token; foreach (var node in path) {