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

GetActivePositionsAsync returning NullReferenceException #12

Closed
basxib opened this issue May 4, 2018 · 3 comments
Closed

GetActivePositionsAsync returning NullReferenceException #12

basxib opened this issue May 4, 2018 · 3 comments

Comments

@basxib
Copy link

basxib commented May 4, 2018

I traced down the error and it's coming from BaseConverter.ReadJson in CryptoExchange project.
Here's the stack trace:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=CryptoExchange.Net
StackTrace:

at CryptoExchange.Net.Converters.BaseConverter`1.<>c__DisplayClass5_0.<ReadJson>b__0(KeyValuePair`2 v) in \CryptoExchange.Net\Converters\BaseConverter.cs:line 28
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at CryptoExchange.Net.Converters.BaseConverter`1.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer) in C:\Users\Ahd-w10\source\repos\CryptoExchange.Net\Converters\BaseConverter.cs:line 32
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)

@JKorf
Copy link
Owner

JKorf commented May 4, 2018

Hi, can you put LogVerbosity on Debug and share the data that was returned? There is an error parsing the returned data.

@basxib
Copy link
Author

basxib commented May 4, 2018

I found out that in BaseConverters.ReadJson() reader.Value was null and this line doesn't check for null before calling .ToString()
var val = Mapping.SingleOrDefault(v => v.Value == reader.Value.ToString()).Key;

I solved it by simply adding a null check like this:
var val = Mapping.SingleOrDefault(v => v.Value == reader.Value?.ToString()).Key;

I saw you solved this on CryptoExchange.net 4 hours ago.
Now it's working like a charm and retrieving the right positions.

@JKorf
Copy link
Owner

JKorf commented May 4, 2018

Ah okay. Yes I noticed there was no error/null checking on that bit so I added that after I saw where your error was coming from, but didn't know for sure if it would solve your problem. Glad it's fixed!

@JKorf JKorf closed this as completed May 4, 2018
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