Under what situations would this code error out with System.StackOverflowException?
Accounts.Sort((x, y) => string.Compare(x.AccountId, y.AccountId));
Update:
the property is written as:
public string AccountId
{
get { return _accountId; }
set { _accountId = value; }
}
Nothing special going on at all. Sort is not overridden either.
Look at the callstack and you will see which function is executed over and over again. If this is not possible (because it is running inside a production environment for example), give more info.
about what the called properties call, where this function is called, etc
If AccountId
does something non-trivial (anything except access a local field) then that is the most likely bet.
An interesting fact is that technically Sort
requires the ordering to be transitive, and string comparison is not always transitive! But this would rarely cause a stackoverflow (unless the Sort
method uses some kind of FP approach); it might cause it to run forever, but I believe the inbuilt types even have this covered (they check for the theoretical max run-length and abort, IIRC).
I would be looking at AccountId
; if it does something "clever" (like lazy-load some value from a parent collection), odds are the bug is in the "clever".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With