title: Strange System.StackOverflowException error in C#, Asp.Net web app
body: <p>This is the weirdest error I have seen and I don't know what the cause is. In VS2013 I have an aspx page using datatables.net and a repeater. The page loads up fine and displays correctly then after a few seconds I get </p>
  
  <blockquote>
    <p>"<strong>An unhandled exception of type 'System.StackOverflowException' occurred in System.Web.dll</strong>" </p>
  </blockquote>
  
  <p>The strange thing is if I do "TOP 76" in my SQL I don't get that error however if I do "TOP 77" or greater and I get that error.</p>
  
  <p>I have done numerous restarts, deleted and recreated the page with different names. Tried removing the datatables.net. I tried replacing single quotes (thinking that might be messing with my mark up). But nothing seems to work. </p>
  
  <p>It's weird because I have the same type/style/code on other pages with more and less data and they all work fine.</p>
  
  <p>Next step is reinstall VS2013 as I can't think of anything else to try. Any help would be much appreciated as I am flummoxed.</p>
  
  <ul>
  <li><p><a href="https://drive.google.com/file/d/0B4nc4jnvyGXcemN2Vklib29SUVk/view?usp=sharing" rel="noreferrer">Click here for the data (csv)</a></p></li>
  <li><p><a href="https://drive.google.com/file/d/0B4nc4jnvyGXcUmktRmVqOVc0WjQ/view?usp=sharing" rel="noreferrer">StackTrace</a></p></li>
  </ul>
  
  <p>This shows 5,000 entries before visual studio gives up</p>
  
  <pre><code>System.Runtime.Serialization.dll!System.Runtime.Serialization.TypeHandleRefEqualityComparer.GetHashCode(System.Runtime.Serialization.TypeHandleRef obj)
      mscorlib.dll!System.Collections.Generic.Dictionary&lt;System.Runtime.Serialization.TypeHandleRef,System.Runtime.Serialization.IntRef&gt;.FindEntry(System.Runtime.Serialization.TypeHandleRef key)
      mscorlib.dll!System.Collections.Generic.Dictionary&lt;System.Runtime.Serialization.TypeHandleRef,System.Runtime.Serialization.IntRef&gt;.TryGetValue(System.Runtime.Serialization.TypeHandleRef key, out System.Runtime.Serialization.IntRef value)
      System.Runtime.Serialization.dll!System.Runtime.Serialization.Json.JsonDataContract.JsonDataContractCriticalHelper.GetId(System.RuntimeTypeHandle typeHandle)
      System.Runtime.Serialization.dll!System.Runtime.Serialization.Json.JsonDataContract.JsonDataContractCriticalHelper.GetJsonDataContract(System.Runtime.Serialization.DataContract traditionalDataContract)
      System.Runtime.Serialization.dll!System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson.WriteDataContractValue(System.Runtime.Serialization.DataContract dataContract, System.Runtime.Serialization.XmlWriterDelegator xmlWriter, object obj, System.RuntimeTypeHandle declaredTypeHandle)
      System.Runtime.Serialization.dll!System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeAndVerifyType(System.Runtime.Serialization.DataContract dataContract, System.Runtime.Serialization.XmlWriterDelegator xmlWriter, object obj, bool verifyKnownType, System.RuntimeTypeHandle declaredTypeHandle, System.Type declaredType)
      System.Runtime.Serialization.dll!System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson.SerializeWithXsiType(System.Runtime.Serialization.XmlWriterDelegator xmlWriter, object obj, System.RuntimeTypeHandle objectTypeHandle, System.Type objectType, int declaredTypeID, System.RuntimeTypeHandle declaredTypeHandle, System.Type declaredType)
      System.Runtime.Serialization.dll!System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize(System.Runtime.Serialization.XmlWriterDelegator xmlWriter, object obj, bool isDeclaredType, bool writeXsiType, int declaredTypeID, System.RuntimeTypeHandle declaredTypeHandle)
      System.Runtime.Serialization.dll!System.Runtime.Serialization.XmlObjectSerializerWriteContextComplex.InternalSerialize(System.Runtime.Serialization.XmlWriterDelegator xmlWriter, object obj, bool isDeclaredType, bool writeXsiType, int declaredTypeID, System.RuntimeTypeHandle declaredTypeHandle)
      [Lightweight Function]
      /* lots of lines omitted */
      System.Runtime.Serialization.dll!System.Runtime.Serialization.Json.JsonCollectionDataContract.WriteJsonValueCore(System.Runtime.Serialization.XmlWriterDelegator jsonWriter, object obj, System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson context, System.RuntimeTypeHandle declaredTypeHandle)
      System.Runtime.Serialization.dll!System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson.WriteDataContractValue(System.Runtime.Serialization.DataContract dataContract, System.Runtime.Serialization.XmlWriterDelegator xmlWriter, object obj, System.RuntimeTypeHandle declaredTypeHandle)
      System.Runtime.Serialization.dll!System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(System.Runtime.Serialization.DataContract dataContract, System.Runtime.Serialization.XmlWriterDelegator xmlWriter, object obj, System.RuntimeTypeHandle declaredTypeHandle)
      System.Runtime.Serialization.dll!System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize(System.Runtime.Serialization.XmlWriterDelegator xmlWriter, object obj, bool isDeclaredType, bool writeXsiType, int declaredTypeID, System.RuntimeTypeHandle declaredTypeHandle)
      System.Runtime.Serialization.dll!System.Runtime.Serialization.XmlObjectSerializerWriteContextComplex.InternalSerialize(System.Runtime.Serialization.XmlWriterDelegator xmlWriter, object obj, bool isDeclaredType, bool writeXsiType, int declaredTypeID, System.RuntimeTypeHandle declaredTypeHandle)
      [Lightweight Function]
      System.Runtime.Serialization.dll!System.Runtime.Serialization.Json.JsonCollectionDataContract.WriteJsonValueCore(System.Runtime.Serialization.XmlWriterDelegator jsonWriter, object obj, System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson context, System.RuntimeTypeHandle declaredTypeHandle)
      System.Runtime.Serialization.dll!System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson.WriteDataContractValue(System.Runtime.Serialization.DataContract dataContract, System.Runtime.Serialization.XmlWriterDelegator xmlWriter, object obj, System.RuntimeTypeHandle declaredTypeHandle)
      System.Runtime.Serialization.dll!System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(System.Runtime.Serialization.DataContract dataContract, System.Runtime.Serialization.XmlWriterDelegator xmlWriter, object obj, System.RuntimeTypeHandle declaredTypeHandle)
      The maximum number of stack frames supported by Visual Studio has been exceeded.
  </code></pre>
  
  <p>Here is the aspx</p>
  
  <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/OxintMaster.master" AutoEventWireup="true" CodeBehind="inactivereport.aspx.cs" Inherits="oxint.com._40.admin.contrib.inactivereport" %&gt;
  &lt;asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"&gt;
      &lt;div class="grid"&gt;
          &lt;div class="row cells12"&gt;
              &lt;div class="cell colspan12"&gt;
                  &lt;h3&gt;Companies assigned to Inactive Contributors Report (&lt;asp:Literal runat="server" ID="litCount" &gt;&lt;/asp:Literal&gt;)&lt;/h3&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;table id="mysearchresultstable" class="dataTable striped" data-page-length='25'&gt;
              &lt;thead&gt;
                  &lt;tr&gt;
                      &lt;th&gt;Contributor&lt;/th&gt;
                      &lt;th style="text-align:center;"&gt;Count&lt;/th&gt;
                      &lt;th style="text-align:center;"&gt;Action&lt;/th&gt;
                  &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;
                  &lt;%try
                    {%&gt;
                  &lt;asp:Repeater runat="server" ID="rptData1"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;tr&gt;
                              &lt;td style="white-space:nowrap;"&gt;
                                  &lt;a href='/admin/contrib/cndisplay.aspx?id=&lt;%#Eval("Items[0].Value")%&gt;'&gt;
                                      &lt;asp:Literal runat="server" ID="litName"&gt;&lt;/asp:Literal&gt;
                                  &lt;/a&gt;
                              &lt;/td&gt;
                              &lt;td style="white-space:nowrap;text-align:center;"&gt;&lt;%#Eval("Items[3].Value")%&gt;&lt;/td&gt;&lt;!--count--&gt;
                              &lt;td style="white-space:nowrap;text-align:center;"&gt;
                                  &lt;a href='/admin/contrib/inactiveview.aspx?id=&lt;%#Eval("Items[0].Value")%&gt;'&gt;&lt;span class="mif-info"&gt;&lt;/span&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/ItemTemplate&gt;
                  &lt;/asp:Repeater&gt;
                  &lt;%}
                    catch (Exception ex) { Response.Write(ex.Message); } %&gt;
              &lt;/tbody&gt; 
          &lt;/table&gt;             
      &lt;/div&gt;
  
  &lt;script&gt;
      $(document).ready(function () {
          /*$.fn.dataTable.moment('dd MMM yyyy HH:mm');*/
          $('#mysearchresultstable').dataTable(
          {
              /*"order": [[1, "asc"]],*/
              /*responsive: true,*/
              "lengthMenu": [25, 50, 100],
              "pagingType": "full",
              "oLanguage": { "sSearch": "Filter:" },
              "aoColumns": [null, null, { "bSortable": false }]
          }
      );
  });
  &lt;/script&gt;
  
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p>Here is the code behind</p>
  
  <pre><code>using ApplicationClasses;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  
  namespace oxint.com._40.admin.contrib
  {
      public partial class inactivereport : System.Web.UI.Page
      {
          private int iCount { get; set; }
  
          protected void Page_Load(object sender, EventArgs e)
          {
              if (!IsPostBack)
              {
                  rptData1.ItemDataBound += rptData1_ItemDataBound;
  
                  string sData = "SELECT contributor.referenceno,contributor.firstname,contributor.lastname,COUNT(contributor.referenceno) As Count " +
                                "FROM ((Contribprofile inner join contributor on Contribprofile.referenceno=contributor.referenceno) " +
                                "inner join Profilecompany on Contribprofile.companyid=Profilecompany.companyid) " +
                                "where Contribprofile.iscurrent =1 and not contributor.status in ('Full','Trial') " +
                                "group by contributor.Referenceno,contributor.firstname,contributor.lastname ";
  
                  rptData1.DataSource = new DataAccessFunctions.DataAccess().GetData(sData, null);
                  rptData1.DataBind();
              }
          }
  
          void rptData1_ItemDataBound(object sender, RepeaterItemEventArgs e)
          {
              GenericData oData = (GenericData)e.Item.DataItem;
  
              iCount += ApplicationSystemFunctions.SystemFunctions.ParseInt(oData.Items[3].Value);
  
              litCount.Text = iCount.ToString();
  
              Literal oLiteral = (Literal)e.Item.FindControl("litName");
  
              oLiteral.Text = string.Format("{0} {1}", oData.Items[1].Value, oData.Items[2].Value.Replace("'", "-"));
          }
      }
  }
  </code></pre>