I have a few projects:
- A database interface project that defines
Thingo
(main solution) - A logic project that defines
ThingoChooser
(plugin solution) - A GUI project that refers to the logic project (plugin solution
- A test project that refers to the logic project (plugin solution)
I'm debugging the plugin, so I run the main solution with its current working directory set to the bin\Debug
directory targeted by all of the plugin projects. The main executable finds the plugin class in the GUI assembly and displays its main form.
In the test project, this code works fine:
this.chooser = new ThingoChooser();
foreach (var thingo in this.chooser.AvailableThingos) {
Console.WriteLine(release);
}
The same code, posted into my GUI project, fails with a StackOverFlowException
when AvailableThingos
returns.
ThingoChooser.AvailableThingos
looks like this:
public IEnumerable<Thingo> AvailableThingos {
get {
// Yes, it DEFINITELY case-matches the private variable,
// NOT the public property. Oh, I wish this were that easy!
return this.availableThingos;
}
private set {
// ...
}
}
… and to what kind of IEnumerable<Thingo>
do I set this.availableThingos
?
It's a List<Thingo>
.
Yes, I have a WinForms app that throws StackOverFlowException
when trying to walk a List<T>
. :)
VS2008 is perfectly happy to let me inspect this.availableThingos
before it's returned. When I click the step button: StackOverflowException
, every time. It also happens out of the debugger.
Fine waves of the dead chicken I've tried, most suggested by commenters, included:
- Looking at the stack trace for loops
- Changing the return type of
AvailableThingos
toList<Thingo>
- Removing
var
in case implicit typing stuffed me up - Making the property's backing store variable
public
and hitting it directly - Changing the backing store to a
List<T>
- Removing LINQBridge and re-targeting to .NET 3.5
The changes don't help, and the stack trace doesn't show any loops. After one click of the “Step Into” button after the }
of the getter, I get the exception warning float-over reading:
StackOverflowException was unhandled
An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll
The bug is at its most dramatic when I switch to .NET 3.5 and remove LINQBridge entirely and change the type of the backing store to List<Thingo>
and access it directly and simply try this from the WinForms code:
List<Thingo> thingos = this.chooser.availableThingos.ToList();
Yep: calling .ToList()
on a List<Thingo>
can blow up with StackOverflowException
.