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?

2
  • Ok. Good to hear it's working for you. Commented Nov 25, 2010 at 11:17
  • Just to say; dynamic can be horribly over-used... this may be one of those times. Commented Nov 25, 2010 at 11:21

1 Answer 1

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)

Sign up to request clarification or add additional context in comments.

2 Comments

awesome, thanks a lot, this site is really a great resource for beginners
@Daniel Joseph: Cheers. Maybe in some future version of the language, your current code "will just work".

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.