chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Stack Overflow Exception will be called when one is mocking static fields.

Here's the production code:
    public  abstract class WrapperClass

        public MyRectSimple rec
        { get; set; }

    public  class MyRectSimple
        public static MyRectSimple Empty = new MyRectSimple();
        public double leftx
        { get; set; }
        public double lefty
        { get; set; }
        public double distanceX
        { get; set; }
        public double distanceY
        { get; set; }


And here's the test code
        [Test, Isolated]
        public void TestRecursive()
            WrapperClass sc = Isolate.Fake.Instance<WrapperClass>(Members.ReturnRecursiveFakes);
            MyRectSimple rec = new MyRectSimple();

If you run using the test runner in, you will get this error:
An existing connection was forcibly closed by the remote host

If you run under the debugger, you will get a stackoverflow exception.

Do solve this as this, along with the previous bug, urgent for me
buy no2
asked by nsoonhui (59.1k points)

1 Answer

0 votes

This is a pretty rare bug that happens when the following are true:
  • * A class being faked with recursive stub has a method returning the problematic class
    * The problematic class has a static field of the same type that initializes itself

The above combined caused an infinite loop when initializing the problematic class.

Thanks for the info that helped recreate this bug. We have already fixed the root cause and I will send you a patched version in the next couple of days. This fix will of course be included in our next version.

Typemock support
answered by doron (17.2k points)