+ Start a Discussion
Anatoliy BaranchykovAnatoliy Baranchykov 

Why I'm getting error System.NullReferenceException in QueryAsync? (Force.Net Toolkit)

Hi everyone.
The code from example works only once for me.
I have method where I'm getting data from the salesforce.
public static async Task QuerySalesForceRestApi()
        {
            ForceClient newClient = new ForceClient(instanceUrl, apiVersion, accessToken, new System.Net.Http.HttpClient());
            var contacts2 = await newClient.QueryAsync<Account>("SELECT  Name From Account");
        }

This method works perfect when I'm try to get data at a first time. The same method not working when I'm try to get data after few seconds. I'm getting error System.NullReferenceException in this line.
var contacts2 = await newClient.QueryAsync<Account>("SELECT  Name From Account");
I've checked that newClient is created properly.
Why this code not working twice?
Thanks!

 
Daniel BallingerDaniel Ballinger
Can you include the stack trace from the exception? It might indicate if the NullReferenceException is occuring in your code or in the toolkit itself.
Austin GAustin G
There could be several reasons for this issue, and unfortunately most potential causes are not the query. The ForceClient query shouldn't return nulls in general, it typically either throws exceptions or returns empty list to indicate 0 results. It may be an issue with how the async calls are happening, and when you're operating on the returned data.