Bug 20082 - C# Dynamic Support for Json.Net's JObject
Summary: C# Dynamic Support for Json.Net's JObject
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:55 UTC by Rodja Trappe
Modified: 2014-05-28 12:38 UTC (History)
3 users (show)

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


Attachments

Description Rodja Trappe 2014-05-28 00:55:40 UTC
Since version 4.0 Json.Net supports dynamic access to an JObject:

    dynamic d = JObject.Parse("{number:1000, str:'string', array: [1,2,3,4,5,6]}");

    Console.WriteLine(d.number);
    Console.WriteLine(d.str);
    Console.WriteLine(d.array.Count);

It would be great to have iOS support for this. However, the dynamic support in Xamarin.iOS 7.2.2 is limited to anonymous types. The above code results in an RuntimeBinderException:

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: `Newtonsoft.Json.Linq.JObject' does not contain a definition for `number'
  at Microsoft.Scripting.Interpreter.ThrowInstruction.Run (Microsoft.Scripting.Interpreter.InterpretedFrame frame) [0x00027] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ControlFlowInstructions.cs:505
  at Microsoft.Scripting.Interpreter.Interpreter.Run (Microsoft.Scripting.Interpreter.InterpretedFrame frame) [0x0001b] in /Developer/MonoTouch/Source/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Interpreter.cs:126
Comment 1 Shruti 2014-05-28 07:59:59 UTC
I have created a sample iOS project and added above code written in description section. I am able to reproduce this issue at runtime.

ScreenCast regarding issue : http://screencast.com/t/iyXeQcRJuM54

Exception Log : https://gist.github.com/saurabh360/6c670267c8057b7d595d

Environment Info :
Xamarin.iOS
Version: 7.2.2.2 (Enterprise Edition)
Hash: db4427f
Branch: 
Build date: 2014-04-22 12:49:14-0400

Note You need to log in before you can comment on or make changes to this bug.