1

I have below type of code snippet.

var PersonList = new List<person>() { 
                new person { Name = "b", Age = 4 },
                new person { Name = "s", Age = 2 },
                new person { Name = "e", Age = 5 },
                new person { Name = "a", Age = 1 },
            }.AsQueryable();

// Now somewhere in usercontrol I am converting that list to dynamic.
dynamic DynaList = PersonList;

// Now below line gives me error when I try to perform any on DynaList.
DynaList.ToList(); // Error - BinderException
DynaList.OrderBy("Name"); // Error - BinderException

Why dynamic is not converting to its type runtime?

k-s
  • 2,140
  • 10
  • 39
  • 72

2 Answers2

2

You can't use extension methods on dynamic types, as if the extension method was a method on the instance. See this SO post and this SO post. You have to use the extension methods on the underlying static class.

Community
  • 1
  • 1
Brian Mains
  • 50,194
  • 35
  • 142
  • 253
  • If you see a duplicate, please vote to close, rather than link it in an answer to scrape some rep. – Rawling Feb 19 '13 at 15:24
0

Extension methods are not supported on dynamic types . Hope this Link will explain you the reason...

skjcyber
  • 5,433
  • 12
  • 36
  • 58