I am developing in MVC 5, and I am receiving an error on a GET that can return multiple records (900+).
This page also POSTs a multiple row update, but I am receiving the infinite loop on the GET. If the page has a lot of records returned (120ish+), I get the infinite loop error. It doesn't seem to happen on pages with fewer records (<100), but even still, the page takes longer to load than I would expect.
Here is the error:
Make sure you don't have an infinite loop or infinite recursion
System.StackOverflowException was unhandled Message: An unhandled exception of type 'System.StackOverflowException' occurred in System.Runtime.Serialization.dll
I am not getting an error on a particular line, but at one point in the disassembly, I saw an error string.EqualsHelper(string, string) + 0x0000000c in process iisexpress.exe. (This doesn't happen everytime the page crashes)
Is there a problem with my code, or is the problem the number of records returned to the page? There are sometimes 900 records on a page. I could add pagination, but having all records on one page is more efficient for the user. The user bulk sets a field value on the page, and then changes the bulk set value for a varied amount of records.
I have tried both a for and a foreach loop, but I had the same error using both methods (and I am not sure what is the best to use in this circumstance).
I have been working on this for awhile, and I am not finding the problem.
Controller
public ActionResult PCPList(string location, string pcp)
{
List<PCPListVM> data = new List<PCPListVM>();
//query
data = (from n in db.DataDump
join t in db.TData on n.SubscriberID equals t.SubscriberID into joinedTable
from td in joinedTable.Take(1).DefaultIfEmpty()
where n.PCP == pcp
orderby n.MemberName
select new PCPListVM()
{
ID = n.ID,
MemberName = n.MemberName,
DateOfBirth = n.DateOfBirth,
PCP = n.PCP,
Location = td.Location,
LocationList = db.LocationList.Select(c => new SelectListItem
{
Value = c.LocationID,
Text = c.LocationList,
Selected = c.LocationList.Equals(location)
}).OrderBy(x => x.Text);
}).ToList();
return View(data);
}
View
@model List<Project.ViewModels.PCPListVM>
// loop through records
@if (Model != null && Model.Count > 0)
{
int j = 0;
foreach (var i in Model)
{
<tr>
<td>@j</td>
<td>@i.SubscriberID</td>
<td>@i.MemberName</td>
<td>@i.DateOfBirth</td>
<td>@i.PCP</td>
<td>
@Html.DropDownListFor(a => a[j].Location, (IEnumerable<SelectListItem>)ViewBag.location, "", new { @class = "input-sm" })
</td>
</tr>
j++;
}
}
Model
public class PCPListVM
{
[Key]
[Required]
public string SubscriberID { get; set; }
public string MemberName { get; set; }
public DateTime? DateOfBirth { get; set; }
public string PCP { get; set; }
public string Location { get; set; }
public IEnumerable<SelectListItem> LocationList { get; set; }
}
Update -
My test case returns 1200 rows. I have also tried removing the dropdowns altogether to see if they were the issue and the page is still crashing. I have checked in the controller and the correct amount of records are being returned to the viewmodel.
After running the profiler, I am seeing this message: System.Reflection..Get.(.*) = 9.01; You may be using Reflection excessively. It is an expensive operation.
Is there a better way for me to pull this data and loop through it?
The error that I see in the call stack is : System.Runtime.Serialization.DataContract.DataContractCriticalHelper.GetId(System.RuntimeTypeHandle)
When doing the LocationList creation, do this:
LocationList = db.LocationList.Select(c => new SelectListItem
{
Value = c.LocationID,
Text = c.LocationList,
Selected = c.LocationList.Equals(location)
}).OrderBy(x => x.Text).ToList()
I'm thinking that Json.NET is having some circular reference problems when trying to serialize the IEnumerable response.
It seemed that the number of records returned was causing a performance issue in this case. I ended up returning my records to a WebGrid and paging by 200, and I am no longer receiving the error messages.
User contributions licensed under CC BY-SA 3.0