2

I have a property declared as type dynamic

 public dynamic Data {get;set;}

later in some method the type of data becomes System.Collections.Generic.List so if use Data.AsQueryable() i get "System.Collections.Generic.List<Entity1 does not contain a definition for 'AsQueryable' " error.

The result has to be converted to Iqueryble and i am using the methods defined in Dynamic.Linq.

How should i proceed?

Novice
  • 2,447
  • 3
  • 27
  • 33

1 Answers1

6

Currently, dynamic doesn't work well with extension methods.

7.6.5.2 Extension method invocations

...if the normal processing of the invocation finds no applicable methods, an attempt is made to process the construct as an extension method invocation. If expr or any of the args has compile-time type dynamic, extension methods will not apply

As is mentioned in this question, the static context (applicable using directives) would have to be made available at run-time for every dynamic call to figure out which extension methods may apply, which is currently not implemented.

Have you tried calling the extension method as a 'normal' static method instead? E.g. (please modify if you intended to call a different method): System.Linq.Queryable.AsQueryable(Data)

Community
  • 1
  • 1
Ani
  • 111,048
  • 26
  • 262
  • 307
  • awesome, thanks a lot, this site is really a great resource for beginners – Novice Nov 25 '10 at 11:20
  • @Daniel Joseph: Cheers. Maybe in some future version of the language, your current code "will just work". – Ani Nov 25 '10 at 11:39