Freigeben über


PEX - invalid detour, process is not instrumented

I got the above error the other day while experimenting with moles. I got it at the below line:

[TestMethod]
public void MyUnitTestMethod()
{
    //some code
    MMyClassToBeTested.Constructor = (myClassObject) => { return; };
    //some code
}

At first I thought maybe I've written the lambda wrong, so re-wrote that. Tried various other things, finally even deleted the test project and re-created it.

Finally i thought... lets go through the documentation again... and there it was.. an attribute to be added.. which does it all...

[TestMethod]
[HostType("Pex")]
public void MyUnitTestMethod()
{
    //some code
    MMyClassToBeTested.Constructor = (myClassObject) => { return; };
    //some code
}

It turns out that since moles require runtime instrumentation, they must be run using the "Pex" HostType. This is achieved by adding the HostType attribute to the test method.

Till my next post.

Regards,

AlD