RuntimeBinderException on inherited interfaces

I get a RuntimebinderException when I call an inherited interface method that passes dynamic as one of the arguments.

I do not understand this behavior.

Here is a complete example:

using System;

class Program
{
    static void Main(string[] args)
    {
        dynamic dyn = new Record();

        IAdvancedTable advTable = new Table();
        ITable table = advTable;

        // works like a charm using the "base-interface"
        table.Insert(dyn);


        // using the inherited interface throws the RuntimeBinderException
        advTable.Insert(dyn);

        Console.ReadKey();
    }
}

public interface ITable
{
    void Insert(Record record);
}

public interface IAdvancedTable : ITable{}

public class Table : IAdvancedTable
{
    public void Insert(Record record){ /*STUB*/ }
}

public class Record{}

There seems to be no recursion in RuntimeBinder to test for "inherited interfaces" on a real interface. But is there a reason for this?

+4
source share

Source: https://habr.com/ru/post/1650540/


All Articles