private void ExceptionHandlingScopeDisposingCallback()
 {
     if (this.m_tryScope != null)
     {
         if (this.m_catchScope == null && this.m_finallyScope == null)
         {
             throw ExceptionHandlingScope.CreateInvalidUsageException();
         }
         ClientAction lastAction = this.m_context.PendingRequest.LastAction;
         if (lastAction == null || !(lastAction is ClientActionExecutionScopeEnd))
         {
             throw ExceptionHandlingScope.CreateInvalidUsageException();
         }
         ClientActionExecutionScopeEnd clientActionExecutionScopeEnd = (ClientActionExecutionScopeEnd)lastAction;
         if (clientActionExecutionScopeEnd.Scope.Name != "CatchScope" && clientActionExecutionScopeEnd.Scope.Name != "FinallyScope")
         {
             throw ExceptionHandlingScope.CreateInvalidUsageException();
         }
     }
 }
 private ChunkStringBuilder BuildQuery()
 {
     SerializationContext serializationContext = this.SerializationContext;
     ChunkStringBuilder chunkStringBuilder = new ChunkStringBuilder();
     XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
     xmlWriterSettings.OmitXmlDeclaration = true;
     xmlWriterSettings.NewLineHandling = NewLineHandling.Entitize;
     XmlWriter xmlWriter = XmlWriter.Create(chunkStringBuilder.CreateTextWriter(CultureInfo.InvariantCulture), xmlWriterSettings);
     xmlWriter.WriteStartElement("Request", "http://schemas.microsoft.com/sharepoint/clientquery/2009");
     xmlWriter.WriteAttributeString("AddExpandoFieldTypeSuffix", "true");
     xmlWriter.WriteAttributeString("SchemaVersion", this.Context.RequestSchemaVersion.ToString());
     xmlWriter.WriteAttributeString("LibraryVersion", "16.0.0.0");
     if (!string.IsNullOrEmpty(this.m_context.ApplicationName))
     {
         xmlWriter.WriteAttributeString("ApplicationName", this.m_context.ApplicationName);
     }
     xmlWriter.WriteStartElement("Actions");
     Stack<ExecutionScope> stack = new Stack<ExecutionScope>();
     foreach (ClientAction current in this.m_queries)
     {
         if (current is ClientActionExecutionScopeStart)
         {
             ClientActionExecutionScopeStart clientActionExecutionScopeStart = (ClientActionExecutionScopeStart)current;
             clientActionExecutionScopeStart.Scope.WriteStart(xmlWriter, serializationContext);
             stack.Push(clientActionExecutionScopeStart.Scope);
         }
         else if (current is ClientActionExecutionScopeEnd)
         {
             ClientActionExecutionScopeEnd clientActionExecutionScopeEnd = (ClientActionExecutionScopeEnd)current;
             if (stack.Count == 0 || stack.Pop() != clientActionExecutionScopeEnd.Scope)
             {
                 throw ExceptionHandlingScope.CreateInvalidUsageException();
             }
             clientActionExecutionScopeEnd.Scope.WriteEnd(xmlWriter, serializationContext);
         }
         else
         {
             current.WriteToXml(xmlWriter, serializationContext);
         }
     }
     if (stack.Count > 0)
     {
         throw ExceptionHandlingScope.CreateInvalidUsageException();
     }
     xmlWriter.WriteEndElement();
     xmlWriter.WriteStartElement("ObjectPaths");
     Dictionary<long, ObjectPath> dictionary = new Dictionary<long, ObjectPath>();
     while (true)
     {
         List<long> list = new List<long>();
         foreach (long current2 in serializationContext.Paths.Keys)
         {
             if (!dictionary.ContainsKey(current2))
             {
                 list.Add(current2);
             }
         }
         if (list.Count == 0)
         {
             break;
         }
         for (int i = 0; i < list.Count; i++)
         {
             ObjectPath objectPath = this.m_context.ObjectPaths[list[i]];
             objectPath.WriteToXml(xmlWriter, serializationContext);
             dictionary[list[i]] = objectPath;
         }
     }
     xmlWriter.WriteEndElement();
     xmlWriter.WriteEndElement();
     xmlWriter.Flush();
     return chunkStringBuilder;
 }