Why do extension methods fail to get resolved for dynamic types?

279 views Asked by At

Possible Duplicate:
Extension method and dynamic object in c#

For example:

var obj = new byte[] { 1, 2, 3 };
dynamic dobj = obj;

dobj.Count(); // fails
Enumerable.Count(dobj); // works
1

There are 1 answers

1
Mark Byers On BEST ANSWER

It doesn't work because knowing which extension method to call requires knowing what the source code looked like before it was compiled (including knowing which using directives were present). At runtime this information is not available. The workaround you are using is a good approach.