I ask the question because whenever I attempt to call an extension method from the Immediate window in Visual Studio 2010 I get the following error:
System.Collections.Generic.IEnumerable' does not contain a definition for 'ToList' and no extension method 'ToList' accepting a first argument of type 'System.Collections.Generic.IEnumerable' could be found (are you missing a using directive or an assembly reference?)
If the Immediate window doesn't support extension methods, then why is it that when I type my variable (of type IEnumerable<QueryFilter>
) followed by a dot, the IntelliSense lists all the extension methods?
There is nothing wrong with what I am typing in the Command window because if I copy and paste it into my code file and run, it works.
With Visual Studio 2012 doing the same thing for the same solution works fine. If I switch back to VS2010 and the problem persists.
This behaviour is caused by Code Contracts, and is not limited to just the Immediate window but also the Conditional Breakpoints window too.
Update March 01, 2016: Found this MSDN Question asking why type resolution is not working in my watch windows. The behaviour described is exactly the same as I experience when using the Immediate Window. The cause is also attributed to CodeContracts and a bug report has been filed on Microsoft Connect. Whether or not the bug is resolve is not indicated.