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

Notification

Icon
Error

Build runner does not support inline dynamics e.g. var myObject = blah.MethodWhichReturnsDynamic()
alexnorcliffe
#1 Posted : Friday, September 2, 2011 5:55:12 PM(UTC)
Rank: Member

Groups: Registered
Joined: 9/2/2011(UTC)
Posts: 23

Thanks: 1 times
Was thanked: 5 time(s) in 5 post(s)
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
Remco
#2 Posted : Friday, September 2, 2011 6:32:54 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,571

Thanks: 862 times
Was thanked: 1176 time(s) in 1097 post(s)
Thanks for reporting this one. I'll have a look at what's happening and will get back to you.
Remco
#3 Posted : Saturday, September 3, 2011 4:08:04 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,571

Thanks: 862 times
Was thanked: 1176 time(s) in 1097 post(s)
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.
alexnorcliffe
#4 Posted : Sunday, September 11, 2011 12:09:18 PM(UTC)
Rank: Member

Groups: Registered
Joined: 9/2/2011(UTC)
Posts: 23

Thanks: 1 times
Was thanked: 5 time(s) in 5 post(s)
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
#5 Posted : Sunday, September 11, 2011 8:40:17 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,571

Thanks: 862 times
Was thanked: 1176 time(s) in 1097 post(s)
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
#6 Posted : Friday, September 16, 2011 9:36:31 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,571

Thanks: 862 times
Was thanked: 1176 time(s) in 1097 post(s)
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
alexnorcliffe
#7 Posted : Friday, September 23, 2011 1:46:07 PM(UTC)
Rank: Member

Groups: Registered
Joined: 9/2/2011(UTC)
Posts: 23

Thanks: 1 times
Was thanked: 5 time(s) in 5 post(s)
Only just noticed your reply! Will take a look now
alexnorcliffe
#8 Posted : Friday, September 23, 2011 2:01:26 PM(UTC)
Rank: Member

Groups: Registered
Joined: 9/2/2011(UTC)
Posts: 23

Thanks: 1 times
Was thanked: 5 time(s) in 5 post(s)
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;
Remco
#9 Posted : Saturday, September 24, 2011 7:50:45 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,571

Thanks: 862 times
Was thanked: 1176 time(s) in 1097 post(s)
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.
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.045 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download