ekonbenefits / impromptu-interface

Static interface to dynamic implementation (duck casting). Uses the DLR combined with Reflect.Emit.
Apache License 2.0
655 stars 67 forks source link

InvalidCastException thrown from InvokeConstructor if passing more than 14 params arguments #9

Closed jdh28 closed 10 years ago

jdh28 commented 10 years ago

I have a class that I'm creating dynamically via Impromptu.InvokeConstructor that has params arguments. If I pass in 14 arguments it works, but 15 causes an InvalidCastException:

System.InvalidCastException: The result type 'ImpromptuParamsArgs.MyClass' of the dynamic binding produced by binder 'Microsoft.CSharp.RuntimeBinder.CSharpInvokeConstructorBinder' is not compatible with the result type 'System.Type' expected by the call site.

Here is some example code:

    class Program
    {
        static void Main(string[] args)
        {
            var parameters = Enumerable.Range(0, 15).Select(i => i.ToString() as object).ToArray();
            var instance = Impromptu.InvokeConstructor(typeof(MyClass), parameters);
            Console.Out.WriteLine(instance.Args);
        }
    }

    public class MyClass
    {
        public readonly string Args;

        public MyClass(params string[] args)
        {
            Args = String.Join(",", args);
        }
    }
jbtule commented 10 years ago

This code is going to be deprecated in ImpromptuInterface and lives on in a library called Dynamitey, so i've moved the issue there. ekonbenefits/dynamitey#3