简体   繁体   中英

Extension methods not working in Visual Studio (Immediate/Watch windows)

When I try to use an extension method in the Immediate or Watch windows, I get the following error:

{method} is not a member of {class}

I'm using Visual Studio Community 2013 Update 4, but the issue exists on multiple PCs here, running varying versions of Visual Studio 2013 and 2015.

It makes no difference whether the extension methods come from the .NET BCL, or are defined in our project. The code itself compiles and runs successfully; the issue is only in Immediate and Watch.

I tried setting all projects to framework 4.5.1, and using the x86 configuration, without result.

Adding Imports System.Linq at the beginning of the code file makes no difference (which makes sense, as System.Linq is already globally imported (Project properties -> References -> Imported namespaces)).

What else can be done?

In any context where System.Linq isn't imported you can call the extension methods as normal static methods instead. So for example, the following did not work for me in the QuickWatch window (where actualVariables is a List):

actualVariables.Select(actualVariables,x=>x.Identity.DisplayName)

Change it to this form and then it works:

System.Linq.Enumerable.Select(actualVariables,x=>x.Identity.DisplayName)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM