Skip to content

Dynamic.InvokeMember throws RuntimeBinderException on async method #34

@fmichellonet

Description

@fmichellonet

Hi,

I'm working with Azure.Data.Tables nuget package and while i'm trying to call an async method on an internal class a RuntimeBinderException is thrown.
Here is a test that highlights this error.

using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Azure.Data.Tables.Models;
using Dynamitey;
using NUnit.Framework;

namespace Azure.Data.Tables.WithDynamitey.Tests
{
    public class WhereAsyncShould
    {
[Test]
        public async Task Failing()
        {
            string tableName = "WhereAsyncShould";
            var serviceClient = new TableServiceClient("UseDevelopmentStorage=true");
            var client = serviceClient.GetTableClient(tableName);
            var restClient = Dynamic.InvokeGet(client, "_tableOperations");


            var response = await Dynamic.InvokeMember(restClient, new InvokeMemberName("QueryEntitiesAsync", false), new object[]
            {
                new InvokeArg("table", tableName),
                new InvokeArg("timeout", (int?)10),
                new InvokeArg("queryOptions", BuildQueryOptions(client)),
                new InvokeArg("cancellationToken", CancellationToken.None)
            });

            Assert.That(response, Is.Not.Null);
        }

        private static dynamic BuildQueryOptions(TableClient tableClient)
        {
            var t = typeof(TableItem).Assembly.GetType("Azure.Data.Tables.Models.QueryOptions");
            var opts = Dynamic.InvokeConstructor(t);
            Dynamic.InvokeSet(opts, "Format", Dynamic.InvokeGetChain(tableClient, "_defaultQueryOptions.Format"));
            return opts;
        }
}

Any help would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions