Ran into an interesting runtime issue after some refactoring and have pinned in down to the following situation.
When passing a property from a dynamic object to a
You situations is a documented bug on Microsoft Connect
A good question this.
It would appear that it's taking the type of the expression at compile time, IInheritEcho
, and not deep-searching the members of inherited interfaces when looking for the method to invoke dynamically.
And ideally the C# runtime binder for a dynamic
expression should behave the same way as the C# compiler - therefore it should see that the IEcho
interface is inherited by IInheritEcho
and it should work.
We can test the hypothesis - i.e. that it's the static typing - by doing this in the first test:
echo = ((dynamic)echomore).EchoString(dynObject.Foo);
Hey presto - the test passes.
So the issue is not that the dynamic binder can't find the method - it's that when the instance whose member is being invoked dynamically is statically typed as an interface, inherited interfaces are not consulted.
In my opinion this behaviour is incorrect.
Please Eric Lippert... be nice...