title: Orderby LINQ stackoverflow exception. Cannot evaluate expression because the current thread is in a stack overflow state.
body: <p>Orderby LINq stackoverflow exception</p>
  
  <ol>
  <li>I have a tree folder which user may check all and display data into grid. The tree is being constructed via column definition and data is being cosntructed via LINQ.</li>
  </ol>
  
  <p>The LINQ is very long that takes in dynamic select, dynamic where and dynamic orderby. All are being passed as string. It works well until all folders are selected and ordered by, that is the time it gives the stackoverflow exception. But when the orderby is removed, it started working again. Removing orderby is out of the question. </p>
  
  <p>How can I prevent this from happening with out having to remove it?</p>
  
  <p>I tried separating the orderby from the whole linq with select and where. The error gets in during the call of this line:</p>
  
  <pre><code>string test = OrderByString(_selectQuery);
              IEnumerable allRowsOrderedBy = allDataRows.AsQueryable().OrderBy(test);//this line throws exception
              return allRowsOrderedBy;
  </code></pre>
  
  <p>OrdebryString is just a method that parses my select query so I can pass it to the orderby:
  an excerpt of what was constructed is this string: </p>
  
  <blockquote>
    <p>"contact_title,contact_firstname,contact_middlename,contact_lastname,contact_preferredname,contact_code,contact_sex,contact_hold,contact_organization,contact_organizationname,contact_home_address_1_"</p>
  </blockquote>
  
  <p>....</p>
  
  <p>There is no stacktrace, just this error:</p>
  
  <blockquote>
    <p>{Cannot evaluate expression because the current thread is in a stack
    overflow state.}</p>
  </blockquote>