Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

NCrunch 2.23 causes InvalidProgramException to be thrown with exception filtering
vesap
#1 Posted : Thursday, June 2, 2016 8:10:26 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 6/2/2016(UTC)
Posts: 1

Using the exception filtering causes the tests to fail due to InvalidProgramException, for example:
Code:

try
{
  // Do something
}
catch ( AggregateException ex ) when ( ex.InnerException is HttpException ) { } // removing when-predicate gets rid of the InvalidProgramException


I tried this on two PCs, other on Win10+VS2015+NCrunch 2.23 and the other on Win7+VS2015+NCrunch 2.19. The latter works fine but the former causes the InvalidProgramException to be thrown. I tried downgrading to NCrunch 2.19 on the Win10 PC but there was no difference.

So it seems like it is some Win10-specific issue. Any ideas how to resolve it?

Thanks!
Remco
#2 Posted : Thursday, June 2, 2016 9:50:16 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,161

Thanks: 964 times
Was thanked: 1296 time(s) in 1202 post(s)
Hi, thanks for sharing this issue.

This is likely being caused by NCrunch's instrumentation. There must be something in the CLR that doesn't like code within the exception filter from being instrumented. It's interesting that this only happens on Windows 10. I'll need to investigate this more before I can arrange a fix.

For the time being, I recommend disabling instrumentation on this code using NCrunch's code coverage suppression comments, for example:

try
{
// Do something
}
//ncrunch: no coverage start
catch ( AggregateException ex ) when ( ex.InnerException is HttpException ) { } // removing when-predicate gets rid of the InvalidProgramException
//ncrunch: no coverage end
brightoniant
#3 Posted : Friday, September 30, 2016 10:17:00 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 7/13/2016(UTC)
Posts: 8
Location: United Kingdom

Was thanked: 1 time(s) in 1 post(s)
Hi Remco

We are also experiencing this issue. Have you had an opportunity to investigate further?

We're running Windows 7, if that makes any difference.

We have a catch on a SqlException, when exception.Number == 2627.
Remco
#4 Posted : Friday, September 30, 2016 11:33:07 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,161

Thanks: 964 times
Was thanked: 1296 time(s) in 1202 post(s)
Hi! Yes, I've managed to isolate and resolve this issue. A fix will be available with 2.27, out within the next couple of days.
brightoniant
#5 Posted : Friday, September 30, 2016 11:48:31 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 7/13/2016(UTC)
Posts: 8
Location: United Kingdom

Was thanked: 1 time(s) in 1 post(s)
Great stuff. What was the cause, out of interest?
Remco
#6 Posted : Friday, September 30, 2016 10:47:42 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,161

Thanks: 964 times
Was thanked: 1296 time(s) in 1202 post(s)
It was actually a bug in Cecil, since fixed in Cecil's main dev branch. It wasn't correctly calculating the max stack size for methods using exception filters. Up until recently, the bug hadn't been a big deal because exception filters weren't available in C#. The issue didn't appear for all methods, because sometimes methods would have other code that would increase the max size of the stack over the required threshold. This made it hard to reproduce without a good code sample. Changing the structure of the method by adding extra method calls outside the exception filter will probably solve it in isolated situations.
Remco
#7 Posted : Sunday, October 2, 2016 6:07:03 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,161

Thanks: 964 times
Was thanked: 1296 time(s) in 1202 post(s)
v2.27 is now available with a fix for this problem - https://www.ncrunch.net/download
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.050 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download