I want to use dynamic ExpandoObjects for a project I'm working on, but it doesn't compile with what I think is the correct configuration.
From what I can see Mono supports the dynamic keyword and ExpandoObject, so I am assuming it is either a configuration issue or somehow it's not possible in Mono for Android.
When I try to use it though, I get the following error messages in Visual Studio 2010:
Error 3 One or more types required to compile a dynamic expression cannot be found. Are you missing references to Microsoft.CSharp.dll and System.Core.dll? D:\HMI\ExpandoTest\ExpandoTest\Activity1.cs 34 17 ExpandoTest
Error 1 Predefined type 'Microsoft.CSharp.RuntimeBinder.Binder' is not defined or imported ExpandoTest
Here is the simple test code:
using System;
using System.Dynamic;
using System.Collections.Generic;
using System.Runtime;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
namespace ExpandoTest
{
[Activity (Label = "ExpandoTest", MainLauncher = true, Icon = "@drawable/icon")]
public class Activity1 : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
// Test the expando stuff
TestExpando();
}
private void TestExpando()
{
dynamic obj = new ExpandoObject();
int x = 10;
obj.x = x; // This line and the next one generate compiler errors
obj["X"] = x;
}
}
}
As the compiler error message states, you need to add a reference to the Microsoft.CSharp assembly in order to use the dynamic keyword: