I'm using NCrunch 1.42.0.12 with VS 2012.
I've seen a strange issue where nullable types aren't assigned default values (for optional params in C#)
public void HasValue(bool? yes = true)
{
if(!yes.HasValue)
throw new Exception("yes is not true");
}
When invoking this method with HasValue(); you'd expected the parameter 'yes' to be set.
Running this through Resharper the optional parameter is set, but through NCrunch it comes out as a null.
I've disabled parallel running of tests as well. I submitted this as a bug report but though I'd get to see any progress/comments here instead.
Build/Test Issues
NCrunch doesn't assign default values to nullable types
Started by derfel on 6,703 views
Remco NCrunch Developer
#3341
05 Dec 2012 04:26 UTC
Hi, thanks for reporting this problem.
The issue appears to be related to NCrunch's instrumentation of the assembly containing this method. For some reason, the instrumentation is dropping a critical piece of metadata (namely, the '= true') from the parameter. Methods calling 'HasValue' will work normally if they are inside the same assembly as this method, although they fail if they call it across assembly boundaries.
I'll see if I can get a fix for this included in 1.43, which is due out within the next few days. Thanks again for reporting the issue and providing the clear steps to reproduce it.
Cheers,
Remco
The issue appears to be related to NCrunch's instrumentation of the assembly containing this method. For some reason, the instrumentation is dropping a critical piece of metadata (namely, the '= true') from the parameter. Methods calling 'HasValue' will work normally if they are inside the same assembly as this method, although they fail if they call it across assembly boundaries.
I'll see if I can get a fix for this included in 1.43, which is due out within the next few days. Thanks again for reporting the issue and providing the clear steps to reproduce it.
Cheers,
Remco
Thanks for the swift response.
Just to add a note, default values work with reference types.
Therefore running the following method works as expected, with bar being assigned the default value "ncrunch"
public void Foo (string bar = "ncrunch") {
}
Just to add a note, default values work with reference types.
Therefore running the following method works as expected, with bar being assigned the default value "ncrunch"
public void Foo (string bar = "ncrunch") {
}
Remco NCrunch Developer
#3385
10 Dec 2012 04:51 UTC
For anyone interested, 1.43 has just been released with a fix for the above problem.
Remco wrote:For anyone interested, 1.43 has just been released with a fix for the above problem.
I can confirm this has been fixed. Thanks Remco!
Post a reply
Log in to reply.