I was getting the "System.InvalidProgramException : Common Language Runtime detected an invalid program" in some of my tests when running ncrunch, but I don't get that problem when using other test runners.
Disabling "Instrument Output Assembly" works and the tests run, but I lose my code coverage visibility and exception inspection via ncrunch pills.
I could not find any information on this issue, but I have narrowed the problem down to a comination of the catch() when() syntax and using the params keyword (if you pass more than 1 item to the params array). This is particularly a problem because we often want to log something in our catches and the logger often uses params for templates.
Quote://THIS TEST PASSES
[Test]
public void NoCatchWhen()
{
try
{
throw new ApplicationException("1");
}
catch (ApplicationException e) //when (e.Message == "1")
{
Console.WriteLine("Testing problem with {0} in {1}", "clr", "ncrunch");
}
}
//THIS TEST PASSES
[Test]
public void CatchWenAndNoLoggingOfParamArgs()
{
try
{
throw new ApplicationException("1");
}
catch (ApplicationException e) when (e.Message == "1")
{
Console.WriteLine("logstatement");
}
}
//THIS TEST PASSES
[Test]
public void WithCatchWhenAndLoggingOfASingleParamArgument()
{
try
{
throw new ApplicationException("1");
}
catch (ApplicationException e) when (e.Message == "1")
{
Console.WriteLine("Testing problem with {0}", "ncrunch-clr");
}
}
//THIS TEST FAILS
[Test]
public void WithCatchWhenAndLoggingOfAMultipleParamArgument()
{
try
{
throw new ApplicationException("1");
}
catch (ApplicationException e) when (e.Message == "1")
{
//attempting to pass 2 or more arguments into the params array in any method results in the whole method returning CLR-error
Console.WriteLine("Testing problem with {0} in {1} because {2}", "clr", "ncrunch", "resons");
}
}
Is there a better fix to this than disabling ncrunch instrumentation?