If you have a method which returns a dynamic, and you specify access to it either implicitly in-line, or via the var keyword, the build fails in NCrunch as if the return were treated as an object rather than dynamic.
var myObject = blah.AsDynamic().SomeProperty; // fails
dynamic myObject = blah.AsDynamic();
myObject.SomeProperty; // works
Another example:
Assert.IsTrue(blah.AsDynamic().SomeProperty); // fails
dynamic myObject = blah.AsDynamic();
Assert.IsTrue(myObject.SomeProperty); // works
The build works fine in MSBuild and VS
Build/Test Issues
Build runner does not support inline dynamics e.g. var myObject = blah.MethodWhichReturnsDynamic()
Started by alexnorcliffe on 12,366 views
Remco NCrunch Developer
#294
02 Sep 2011 18:32 UTC
Thanks for reporting this one. I'll have a look at what's happening and will get back to you.
Remco NCrunch Developer
#306
03 Sep 2011 16:08 UTC
I've had a good look at this one in the context of the solution you're building in. It seems that NCrunch has a compatibility issue with the DLR where dynamic types are being shared between assemblies.
A workaround to this is to turn off instrumentation for the assembly exposing the dynamic type. This does mean you'll lose code coverage on that assembly, but projects that depend upon it should be able to build.
The dynamic type should still work with the instrumentation provided it isn't being used across assembly boundaries .. so you may also be able to work around this by restructuring your code.
I've noted the issue down to be fixed, though unfortunately it's quite complex so the fix won't be ready in time for the upcoming 1.33b release.
A workaround to this is to turn off instrumentation for the assembly exposing the dynamic type. This does mean you'll lose code coverage on that assembly, but projects that depend upon it should be able to build.
The dynamic type should still work with the instrumentation provided it isn't being used across assembly boundaries .. so you may also be able to work around this by restructuring your code.
I've noted the issue down to be fixed, though unfortunately it's quite complex so the fix won't be ready in time for the upcoming 1.33b release.
Thanks for taking a look at this! For now I've just explicitly declared the offending variables as 'dynamic' rather than implicit typing, as the NCrunch instrumentation is more valuable :)
Remco NCrunch Developer
#357
11 Sep 2011 20:40 UTC
Thanks again for the report. I've updated the build issues page on the wiki to include a note for it, as it seems others are also being affected by it.
Remco NCrunch Developer
#382
16 Sep 2011 09:36 UTC
Hi Alex,
I've been trying today to reproduce this issue so I can properly fix it, though it seems to have mysteriously disappeared for me.
I'm wondering if you have any other way to reproduce it in v1.33b? I've tried using the code you've described above and also through manipulating a few things in a checked out copy of Umbraco, and it always seems to build fine.
I'm starting to wonder if perhaps it was actually a symptom of another issue already fixed ...
Cheers,
Remco
I've been trying today to reproduce this issue so I can properly fix it, though it seems to have mysteriously disappeared for me.
I'm wondering if you have any other way to reproduce it in v1.33b? I've tried using the code you've described above and also through manipulating a few things in a checked out copy of Umbraco, and it always seems to build fine.
I'm starting to wonder if perhaps it was actually a symptom of another issue already fixed ...
Cheers,
Remco
Only just noticed your reply! Will take a look now
Here you go. Stick this function in one assembly:
public static dynamic MyFunction()
{
return string.Empty;
}
Stick this in another assembly - 1.33b fails to build although VS builds it fine:
dynamic myObject = MyClass.MyFunction().Empty;
The NCrunch build error is:
[15:02:19.5423-BuildTask-42] ERROR (Compilation): Umbraco.Hive: ProviderGrouping\GroupedSessionExtensions.cs (88): 'object' does not contain a definition for 'Empty' and no extension method 'Empty' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
Changing that code to the following builds fine in both:
dynamic myObject = MyClass.MyFunction();
var blah = myObject.Empty;
public static dynamic MyFunction()
{
return string.Empty;
}
Stick this in another assembly - 1.33b fails to build although VS builds it fine:
dynamic myObject = MyClass.MyFunction().Empty;
The NCrunch build error is:
[15:02:19.5423-BuildTask-42] ERROR (Compilation): Umbraco.Hive: ProviderGrouping\GroupedSessionExtensions.cs (88): 'object' does not contain a definition for 'Empty' and no extension method 'Empty' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
Changing that code to the following builds fine in both:
dynamic myObject = MyClass.MyFunction();
var blah = myObject.Empty;
Edited 23 Sep 2011 14:01 UTC
Remco NCrunch Developer
#416
24 Sep 2011 19:50 UTC
I gave this another go, though it didn't recur for me in 1.34b ... so I'm thinking that it's likely been fixed. Anyway, 1.34b is out today, so you're welcome to give it a try and see if this fixes it for you.
Post a reply
Log in to reply.