ExecuteQuery failing on Initializing an object CSOM RRS feed

  • Question

  • Hi Guys, 

    Anyone had the same problem of calling ExecuteQuery but the object still didn't initialize sometimes.

    So I have a retry code: 

            public static void ExecuteQueryWithIncrementalRetry(this ClientContext clientContext, int retryCount, int delay)
                int retryAttempts = 0;
                if (retryCount <= 0)
                    throw new ArgumentException("Provide a retry count greater than zero.");
                if (delay <= 0)
                    throw new ArgumentException("Provide a delay greater than zero.");
                while (retryAttempts < retryCount)
                    catch (WebException ex)
                        var response = ex.Response as HttpWebResponse;
                        if (response.StatusCode == (HttpStatusCode)429 || response.StatusCode == (HttpStatusCode)503)
                            Thread.Sleep(delay*50 * 1000);
                throw new MaximumRetryAttemptedException("Maximum retry attempts " + retryCount + "has be attempted.");

    This is a strip version of Retry Increment here:

    Why a strip version? Because for some reason the Response catch is sometimes null which leads the script to fail. 

    But now the problem became sometimes it doesn't initialize. 
    The exact error code is "The data is not available. The query may not have been executed." even though it did because it my calls, I have 10 retries and 500 seconds delay total. 

    What I notice in the 3 transcript is that after it only retries once or twice then it will say it is successful but it didn't load the objects properly. 

    Any ideas? 

    Thursday, July 25, 2019 5:14 PM