Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dynamic in android xamarin

i have seen in the link below: Can execute Code Dynamically in monotouch?

that it is impossible to use dynamic in ios xamarin. how about in Andoid xamarin?

I tried to do the following:

            dynamic MyDynamic = new System.Dynamic.ExpandoObject();
            MyDynamic.A = "A";
            MyDynamic.B = "B";

However, when I want to access MyDinamic.A, it says that Unknown Member: A.

Can someone please help? Thanks.

Edit:I also have added the Microsoft.Csharp dll in the solution reference as per the screenshot:

enter image description here

like image 291
jay Avatar asked Dec 28 '16 13:12

jay


2 Answers

I'm not sure which IDE did you use for developing your xamarin android app, by my side I used VS2015, and the error is

Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'

This is because when use the dynamic keyword in your project. The assembly contains the C# runtime binder. To solve this issue, we need to add reference to Microsoft.CSharp library(Microsoft.CSharp.dll) in our project:

enter image description here

After adding this reference, your code runs well by my side.

But I'm not sure if the Xamarin.Android will limit the use of dynamic object, through I didn't find any limitation in xamarin's official document. For more information about dynamic object, you can refer to:

System.Dynamic.DynamicObject Class

System.Dynamic.ExpandoObject Class

like image 180
Grace Feng Avatar answered Sep 28 '22 08:09

Grace Feng


Go to NuGet Package Manager > Manage NuGet packages menu. Then change Source to Microsoft Visual Studio Offline Packages. After adding, it should compile successfully.

1

like image 40
Spurs Lee Avatar answered Sep 28 '22 09:09

Spurs Lee