Home

Linqpad Crash

Following code snippet can consistently reproduce the crash in linqpad v4.51.03 -

void Main() { new MoreDerived(string.Empty); } // Define other methods and classes here class Base { public static List<Base> t = new List<Base>(); public Base() { Console.WriteLine("Base constructor"); if (this is Derived) (this as Derived).DoIt(); // would deref null if we are constructing an instance of Derived Blah(); // would deref null if we are constructing an instance of MoreDerived t.Add(this); // would deref null if another thread calls Base.t.GetLatest().Blah(); // before derived constructor runs } public virtual void Blah() { } } class Derived : Base { readonly MoreDerived derivedFoo = new MoreDerived("Derived initializer"); public void DoIt() { derivedFoo.Bar(); } public virtual void Bar(){DoIt();} } class MoreDerived : Derived { public MoreDerived(string something){} public override void Bar() { DoIt(); } }

Comments

  • That is because when a MoreDerived is created, it's base class member "derivedFoo" tries to create another MoreDerived and it causes an infinite loop, ultimately bringing a StackOverflowException.

    This exception is not catchable by the current (stable) version of linqpad, and so it takes the host down.

    In the latest beta, queries are isolated by process, and so only the process of the query is taken down, leaving LinqPad untouched. Try it with the latest beta and you will find a message on the top of the query saying "Query ended unexpectedly because an uncatchable exception was thrown."
Sign In or Register to comment.