Bug 20081 - C# Dynamic Support for ExpandoObject
Summary: C# Dynamic Support for ExpandoObject
Status: CONFIRMED
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime (show other bugs)
Version: 7.2.2
Hardware: Macintosh Mac OS
: Normal enhancement
Target Milestone: Untriaged
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2014-05-28 00:17 UTC by Rodja Trappe
Modified: 2014-09-13 15:26 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 20081 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Comment 1 Rodja Trappe 2014-05-28 00:29:24 UTC
Since 7.2 there is some support for C# dynamic feature. While accessing properties in anonymous types seems to work, accessing them in an ExpandoObject does not:

    dynamic data = new { Name = "test" };
    Console.WriteLine (data.Name); // runs fine with 7.2 on iOS

    dynamic x = new ExpandoObject();
    x.NewProp = "string.Empty"; // this still works
    Console.WriteLine(x.NewProp); // fails with 7.2 on iOS

The last line results in a runtime exception:

System.NotImplementedException: Interpreter of ref types
  at Microsoft.Scripting.Interpreter.LightCompiler.CompileMethodCallExpression (System.Linq.Expressions.Expression expr) [0x00075] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:1286
  at Microsoft.Scripting.Interpreter.LightCompiler.CompileNoLabelPush (System.Linq.Expressions.Expression expr) [0x001ba] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:1645
  at Microsoft.Scripting.Interpreter.LightCompiler.Compile (System.Linq.Expressions.Expression expr) [0x00008] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:1732
  at Microsoft.Scripting.Interpreter.LightCompiler.CompileConditionalExpression (System.Linq.Expressions.Expression expr, Boolean asVoid) [0x00007] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:821
  at Microsoft.Scripting.Interpreter.LightCompiler.CompileNoLabelPush (System.Linq.Expressions.Expression expr) [0x001d2] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:1647
  at Microsoft.Scripting.Interpreter.LightCompiler.Compile (System.Linq.Expressions.Expression expr) [0x00008] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:1732
  at Microsoft.Scripting.Interpreter.LightCompiler.Compile (System.Linq.Expressions.Expression expr, Boolean asVoid) [0x00012] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:1596
  at Microsoft.Scripting.Interpreter.LightCompiler.CompileBlockExpression (System.Linq.Expressions.Expression expr, Boolean asVoid) [0x00028] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:379
  at Microsoft.Scripting.Interpreter.LightCompiler.CompileNoLabelPush (System.Linq.Expressions.Expression expr) [0x003d0] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:1686
  at Microsoft.Scripting.Interpreter.LightCompiler.Compile (System.Linq.Expressions.Expression expr) [0x00008] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:1732
  at Microsoft.Scripting.Interpreter.LightCompiler.Compile (System.Linq.Expressions.Expression expr, Boolean asVoid) [0x00012] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:1596
  at Microsoft.Scripting.Interpreter.LightCompiler.CompileConditionalExpression (System.Linq.Expressions.Expression expr, Boolean asVoid) [0x00071] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:831
  at Microsoft.Scripting.Interpreter.LightCompiler.CompileNoLabelPush (System.Linq.Expressions.Expression expr) [0x001d2] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:1647
  at Microsoft.Scripting.Interpreter.LightCompiler.Compile (System.Linq.Expressions.Expression expr) [0x00008] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:1732
  at Microsoft.Scripting.Interpreter.LightCompiler.CompileGotoExpression (System.Linq.Expressions.Expression expr) [0x0001f] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:958
  at Microsoft.Scripting.Interpreter.LightCompiler.CompileNoLabelPush (System.Linq.Expressions.Expression expr) [0x0042d] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:1692
  at Microsoft.Scripting.Interpreter.LightCompiler.CompileAsVoid (System.Linq.Expressions.Expression expr) [0x00085] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:1623
  at Microsoft.Scripting.Interpreter.LightCompiler.Compile (System.Linq.Expressions.Expression expr, Boolean asVoid) [0x00006] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:1594
  at Microsoft.Scripting.Interpreter.LightCompiler.CompileConditionalExpression (System.Linq.Expressions.Expression expr, Boolean asVoid) [0x00071] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:831
  at Microsoft.Scripting.Interpreter.LightCompiler.CompileNoLabelPush (System.Linq.Expressions.Expression expr) [0x001d2] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:1647
  at Microsoft.Scripting.Interpreter.LightCompiler.CompileAsVoid (System.Linq.Expressions.Expression expr) [0x00085] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:1623
  at Microsoft.Scripting.Interpreter.LightCompiler.CompileBlockStart (System.Linq.Expressions.BlockExpression node) [0x000b0] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:405
  at Microsoft.Scripting.Interpreter.LightCompiler.CompileBlockExpression (System.Linq.Expressions.Expression expr, Boolean asVoid) [0x00007] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:376
  at Microsoft.Scripting.Interpreter.LightCompiler.CompileNoLabelPush (System.Linq.Expressions.Expression expr) [0x003d0] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:1686
  at Microsoft.Scripting.Interpreter.LightCompiler.Compile (System.Linq.Expressions.Expression expr) [0x00008] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:1732
  at Microsoft.Scripting.Interpreter.LightCompiler.CompileTop (System.Linq.Expressions.LambdaExpression node) [0x00055] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs:221
  at Microsoft.Scripting.Generation.CompilerHelpers.LightCompile (System.Linq.Expressions.LambdaExpression lambda) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Generation/CompilerHelpers.cs:619
  at System.Linq.Expressions.Compiler.LambdaCompiler.Compile (System.Linq.Expressions.LambdaExpression lambda, System.Runtime.CompilerServices.DebugInfoGenerator debugInfoGenerator) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq.Expressions.Interpret/LambdaCompiler.cs:41
  at System.Linq.Expressions.Expression`1[System.Func`3[System.Runtime.CompilerServices.CallSite,System.Object,System.Object]].Compile () [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Scripting.Core/Ast/LambdaExpression.cs:188
  at System.Runtime.CompilerServices.CallSiteBinder.BindCore[Func`3] (System.Runtime.CompilerServices.CallSite`1 site, System.Object[] args) [0x00059] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Scripting.Core/Actions/CallSiteBinder.cs:148
  at System.Dynamic.UpdateDelegates.UpdateAndExecute1[Object,Object] (System.Runtime.CompilerServices.CallSite site, System.Object arg0) [0x0010d] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Scripting.Core/Actions/UpdateDelegates.Generated.cs:255
  at DynamicSupportOniOS.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x00144] in /Users/trappe/Projects/Spikes/DynamicSupportOniOS/AppDelegate.cs:41
  at at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
  at DynamicSupportOniOS.Application.Main (System.String[] args) [0x00008] in /Users/trappe/Projects/Spikes/DynamicSupportOniOS/Main.cs:16
Comment 2 Ram Chandra 2014-05-28 08:43:07 UTC
I have checked this issue and I am able to reproduce this issue

Steps to reproduce:
1. Create a iPhone "Single View Application" in XS
2. Add "Microsoft.CSharp" reference to the project.
3. Add the following code in the "Main()" method of "Main.cs" file.
            
            dynamic data = new { Name = "test" };
            Console.WriteLine (data.Name); 

            dynamic x = new ExpandoObject();
            x.NewProp = "string.Empty"; 
           Console.WriteLine(x.NewProp); 

4.  use the "using System.Dynamic;" namespace
5. Build and deploy the application.
6. An exception is thrown i.e. "System.NotImplementedException: Interpreter of ref types"

I observed that when I added a new property to an instance of the "ExpandoObject" class and trying to access the values of that property I am getting "System.NotImplementedException" exception. 

I have also tried the same code with "console project" and "android project" and it is working with both of these project. I am able to access the values of the property. 

Screencast: http://www.screencast.com/t/NPbAZWzHH

Application output log : https://gist.github.com/saurabh360/9b2144049e820e59ee79

Environment Info:

Mac OS X 10.9.2

Xamarin Studio: 5.0 (build 876)
Xamarin.iOS : 7.2.2.2 

Build Information
Release ID: 500000876
Git revision: 892675cba83be2d00954bfdf22dd8a29e6a47502
Build date: 2014-05-21 13:56:57-04
Xamarin addins: c62ebd0f0c296c5773c7b92ad06d5b5b487f40e8
Comment 3 Michael 2014-06-22 16:43:32 UTC
Just curious, isn't this known/expected behavior?  According to this resource:
http://developer.xamarin.com/guides/ios/advanced_topics/limitations/

DLR is not supported in iOS.  It would be nice to know if is the case, or if this has been updated/fixed/addressed/upgraded/etc.  I am researching Xamarin and would like to use DLR in my project.  Thank you!
Comment 4 frederic torres 2014-09-13 13:27:07 UTC
All JIT compilation and DLR are not supported for iOS and Xamarin.iOS.

You could write your own kind of expando object using IDctionary or for more complex dynamic stuff

You could use Jint, a JavaScript v5 runtime written in a C# portable library that works really well for Xamarin.iOS and Android.

https://github.com/sebastienros/jint
http://frederictorres.blogspot.com/2014/04/jint-tutorials.html
Comment 5 Michael 2014-09-13 13:54:18 UTC
Thank you for the tip, Frederic.

What I am mostly interested in is Aspect-Oriented Programming, or interception.  Specifically, I would like to port the Enterprise Library Interception Block to a Xamarin.iOS Portable Library:

http://msdn.microsoft.com/en-us/library/ff647107.aspx

Would it be possible to leverage Jint to do this?

Thanks again,
Michael
Comment 6 frederic torres 2014-09-13 15:09:04 UTC
From what I just read about the Enterprise Library Interception Block, 

"... dynamically insert code that provides support for crosscutting concerns"

You cannot do that on iOS, it is not allowed by Apple.

Would it be possible to leverage Jint to do this? No.

What you can do with Jint is execute some JavaScript code in your C# app running on iOS. So you get some of the dynamic language functionality around your app and your objects but not around the execution framework.

You can create a totally dynamic object in JavaScript and access it from C# by getting a IDictionary representation.

See my blog post mentioned above about some tutorials.

Jint can be compiled in C# app for Android, Windows, MacOS, Linux, iOS.

Fred.
Comment 7 Michael 2014-09-13 15:26:26 UTC
OK, this is good to know, Fred.  Thanks for the information.  I will have to investigate further and probably open a forum post on the very active Xamarin community forums.  I know there's Ahead-of-Time Compilation as well, and I am wondering if AOP can be achieved via that technique.  I'm a newb here so lots to learn.

Thanks again,
Michael