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
0 votes
I'm not sure if this is a problem with TypeMock or the way Microsoft handles instrumentation of assemblies, but since the problem disappears when I disable TypeMock, I'll report it here.

The problem was first seen in a test for some parts of our production code. However, to simplify matters I have reproduced the problem in the sample code below (i.e. the code is pointless, but it does illustrate the problem):

namespace UnitTestProblems {
    public class MockProblems {
        public static bool DoSomething() {
            try {
                return Helper.Help();
            } catch (MyException e) {
                Console.WriteLine(e);
                return false;
            }
        }
    }

    public class Helper {
        public static bool Help() {
            throw new MyException();
        }
    }

    public class MyException : Exception {
    }
}


[TestMethod]
public void TestMethod() {
   Assert.IsFalse(MockProblems.DoSomething());
}


I'm perfectly aware that the above code doesn't use any TypeMock features. The test project includes a reference to TypeMock though.

However, if TypeMock and instrumentation is enabled MyException isn't caught in the catch block. The code will fail with an unhandled exception of type MyException?! I.e. there's something completely wrong here, cause the exception should have been caught by the catch block.

If TypeMock or instrumentation is disabled, everything works fine.

The problem was encountered when we used TypeMock to throw the exception, but as the code shows it can be reproduced without using TypeMock for this.

Similarly, if the catch block is modified as shown below

            } catch (Exception ee) {
                MyException e = ee as MyException;
                Console.WriteLine(e);
                return false;
            }


everything is fine as well.

If MyException is move to another assembly the problem goes away as well.

As the problem cannot be produced without the presence of TypeMock, I take it that the chaining of instrumentation and TypeMock is somehow faulty and I would appreciate any input on the matter.

Regards,
Brian
asked by brian.rasmussen (7.2k points)

4 Answers

0 votes
Hi Brian.
I tried your test program but couldn't create the problem.
Can you please tell me what version of TypeMock are you using?
answered by ohad (35.5k points)
0 votes
That's odd. Remember to turn on both TypeMock and instrumentation.

I have reproduced it with 4.01 and 4.03.

Is there anything else I can do to give you more input?

Thanks,
Brian
answered by brian.rasmussen (7.2k points)
0 votes
Hi Brian
Sorry I didn't realize I need to turn on MS coverage.
I reproduced the problem.
We will fix it and I'll send you the patch.
answered by ohad (35.5k points)
0 votes
Hi Brian
I sent you the fix.
Please check it out.
answered by ohad (35.5k points)
...