After debugging it turned out that the comparison between S.First()
and its successors returned 1
, which - for some reason - meant that S
thought its order was broken and therefore refused to remove the element.
Changing this.NumTerminals > other.NumTerminals
to this.NumTerminals >= other.NumTerminals
seems to have fixed the problem.
It is strange, however, that no specific feedback is presented to the user when such a thing happens. Anyway, thanks Marshall for the help!