Daily Usage Issues

TargetInvocationException

Started by ericschmidt on 6,247 views

I have several tests that seem to randomly fail because of a TargetInvocationException. If I re-run the tests, they pass. This has started to make things extremely difficult to understand if a failing test is actually failing or not. Any idea what might be causing this issue to occur?
Hi,

This smells like sequence dependent behaviour.

When you re-run a test specifically, NCrunch will launch it in a new process. Thus all existing state is cleared. If the test is failing because of state left by a previously executed test in the process, it will always pass when run in a new process.

After a test fails in this manner, try running it via the 'Advanced->Debug selected test in existing task runner process'. This should allow you to get a debugger on the test when it misbehaves and hopefully learn more about the problem.
Thank you, I'll try that and see if I can figure out what's causing it.
I tried your suggestion of debugging using the existing task runner project, but even that resulted in a passing test. I have noticed that our project has a "Abnormal runtime assembly reference resolution detected" warning that shows up. Is it possible that this is causing the TargetInvocationExceptions? Or is there something else I should look for?
ericschmidt wrote:I tried your suggestion of debugging using the existing task runner project, but even that resulted in a passing test. I have noticed that our project has a "Abnormal runtime assembly reference resolution detected" warning that shows up. Is it possible that this is causing the TargetInvocationExceptions? Or is there something else I should look for?


It's possible that this could be causing the problem. NCrunch gives this warning when it detects an assembly being loaded by the CLR from the wrong place. If the assembly also happens to be different to the intended target, this could create problems.

Try turning on the preload assembly references setting for your test project to see if this makes any difference.

Are you able to be any more specific about the TargetInvocationException you're receiving? Is this being thrown within your own code?
I'm pretty sure I found my problem. It turns out there was some PropertyChanged logic that was executing in a specific context that was causing the exception. I thought it was something else because of the TargetInvocationException and didn't look closely enough and the InnerException's being thrown. Thanks for pointing out to double check that.

Post a reply

Log in to reply.