title: Sharepoint Client Object Model The property or field has not been initialized
body: <p>I have a C# program that manages Sharepoint lists using the Sharepoint Client Object Model. Occasionally  we will have server issues which will prevent the program from accessing the sharepoint server. I am using a helper class to run the ExecuteQuery method and have exception handling to continue to execute until there is no exception.</p>
  
  <pre><code>       private void ExecuteContextQuery(ref ClientContext siteContext)
      {
          int timeOut = 10000;
          int numberOfConnectionErrors = 0;
          int maxNumberOfRetry = 60;
  
              while (numberOfConnectionErrors &lt; maxNumberOfRetry)
              {
                  try
                  {
                      siteContext.ExecuteQuery();
                      break;
                  }
                  catch (Exception Ex)
                  {
  
                      numberOfConnectionErrors++;
                      Service.applicationLog.WriteLine("Unable to connect to the sharepoint site. Retrying in " + timeOut);
                      Service.applicationLog.WriteLine("Exception " + Ex.Message + " " + Ex.StackTrace);
                      System.Threading.Thread.Sleep(timeOut);
                      if (numberOfConnectionErrors == maxNumberOfRetry)
                      {
                          throw Ex;
                      }
  
                  }
           }
  
      }
  </code></pre>
  
  <p>However I getting an error messages </p>
  
  <blockquote>
    <p>The property or field 'LoginName' has not been initialized. </p>
  </blockquote>
  
  <p>and </p>
  
  <blockquote>
    <p>collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.</p>
  </blockquote>
  
  <p>The error messages seem to be related to methods where I call the Load method. here is an example of my code that calls the method above.</p>
  
  <pre><code>                List sharepointList = siteContext.Web.Lists.GetByTitle(this._listName);
              CamlQuery query = CamlQuery.CreateAllItemsQuery();
              items = sharepointList.GetItems(query);
  
              siteContext.Load(items);
  
              //siteContext.ExecuteQuery();
              ExecuteContextQuery(ref siteContext);
  </code></pre>
  
  <p>Do I need to reload the site context with every call to ExecuteQuery? Is that why I am seeing the error message above?</p>
  
  <p>Here is the function I am using for getting the Login ID which is generating the error</p>
  
  <pre><code>    public String getLoginIDbyUserId(int userID)
      {
          ClientContext siteContext = getClientContextObject();
          User _getUser = siteContext.Web.SiteUsers.GetById(userID);
  
          siteContext.Load(_getUser);
          //siteContext.ExecuteQuery();
          ExecuteContextQuery(ref siteContext);
  
          String loginID = String.Empty;
          String formatedLoginID = String.Empty;
          loginID = _getUser.LoginName;
          if (loginID.Contains('|'))
          {
  
              formatedLoginID = loginID.Substring(loginID.IndexOf('|') + 1);
  
          }
          siteContext.Dispose();
          return formatedLoginID;
      }
  </code></pre>