Search code examples
asp.netsql-serverlinq-to-sqlstack-overflow

StackOverflow error when calling DataContext.SubmitChanges()


In a hybrid asp.net web application, framework 4.5.1, using LINQ to SQL (not Entity Framework) I'm getting the exception

"An unhandled exception of type 'System.StackOverflowException' occurred in System.Data.Linq.dll"

on any call to DataContext.SubmitChanges().

Every call to SubmitChanges() causes the error, it does not matter what specific entity is being altered. The error is thrown immediately (unlike most StackOverflow exceptions, which normally take a few seconds to occur while the errant code overflows the stack).

The asp.net web application is running on my local host in IIS express using Visual Studio 2013. The database is SQL Server 2005.

My question is, how does one debug a StackOverflow exception in this environment? Right now the above error message is all I get.

  1. The Event Viewer notes that the browser crashed (it happens in both IE 11 and Chrome) but nothing about the LINQ to SQL exception.
  2. The SQL Server process monitor does not register any database call.
  3. I have a log hooked up to my DataContext but it records nothing.

It appears the stack overflow is happening inside System.Data.dll before any database call occurs and before anything can be logged.

This suddenly started happening several hours ago, after a windows update ran and the machine rebooted. That might be a coincidence.

Something else extremely odd: we have four developers in our shop, all using Visual Studio 2013. Two of us suddenly began having this problem, and two of us never had it. We're all running identical code and hitting the same database. The two of us having the problem rebooted, and the problem disappeared on one machine, but is still occurring on my machine.

In addition to rebooting, I've deleted the project from machine and pulled it down from source control so that it is identical to what my 3 co-workers have, deleted all temporary internet files on my machine, and deleted all of my AppData\Local\temp files for my login.

Is there any way to debug this issue?

Clip of call stack when exception occurs (the calls to VisitExpression and etc repeat many dozens of times until it ends).

enter image description here


Solution

  • The unsatisfying "answer" in this case was to delete the *.dbml file and re-create it. That fixed the stack overflow error.

    My comment in reply to @GertArnold above was not accurate. Only one DataContext was throwing the stack overflow exception. It was doing it for every entity in the DataContext, but other DataContexts in the application were working properly.

    This particular *.dbml file has been growing over the years to gargantuan size. While re-creating I was careful to only add database objects that are being referenced, which resulted in a much smaller *.dbml file, which might itself have fixed the problem.