Dynamic runtime fails to find method from a base interface during runtime - by TimwiTerby

Status : 

  Won't Fix<br /><br />
		Due to several factors the product team decided to focus its efforts on other items.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 597276 Comments
Status Closed Workarounds
Type Bug Repros 2
Opened 9/12/2010 12:52:20 PM
Access Restriction Public


Consider the following example program:

namespace Example
    interface IBase<T> { bool Method(T value); }
    interface IDerived<T> : IBase<T> { }
    public class Impl<T> : IDerived<T>
        public bool Method(T value) { return false; }

    class Program
        static void Main(string[] args)
            dynamic d = 1;

            IBase<dynamic> s1 = new Impl<dynamic>();
            System.Console.WriteLine(s1.Method(d));  // works

            IDerived<dynamic> s2 = new Impl<dynamic>();
            System.Console.WriteLine(s2.Method(d));  // fails

In the first dynamic invocation, the DLR correctly finds the method IBase<object>.Contains(object) and calls it with a boxed integer.

In the second dynamic invocation, a RuntimeBinderException is thrown: “No overload for method 'Method' takes '1' arguments.”

This is clearly incorrect as the only overload that exists takes exactly that number of arguments.
Sign in to post a comment.
Posted by Alex [MSFT] on 4/6/2011 at 3:41 PM
Thanks for reporting this issue you've encountered with Visual Studio!

This was an area we explicitly scoped out due to time when shipping C# 4.0 and we'd love to revisit this. This specific case of ISet/IList methods that are actually defined on ICollection is the most visible place where not digging up through parent interfaces unnecessarily limits the reach of dynamic binding in C#.

We hope to add such support soon, though this issue currently falls just below our bug triage cut line. We're marking the issue Won't Fix to indicate that we're not currently tracking to fix this issue in the next release of Visual Studio. We'll reactivate this bug over the next year if we get further than expected through our bug triage list, or if we revisit the bug for the following release.

Alex Turner
Program Manager
Visual Basic and C# Compiler
Posted by Microsoft on 9/12/2010 at 5:02 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Posted by Andrey Breslav on 9/12/2010 at 1:08 PM
See a discussion at: http://stackoverflow.com/q/3696047/445715
that motivated this bug-report