Extension methods must be defined in a non-generic static class
Add keyword static
to class declaration:
// this is a non-generic static class
public static class LinqHelper
{
}
if you do not intend to have static functions just get rid of the "this" keyword in the arguments.
A work-around for people who are experiencing a bug like Nathan:
The on-the-fly compiler seems to have a problem with this Extension Method error... adding static
didn't help me either.
I'd like to know what causes the bug?
But the work-around is to write a new Extension class (not nested) even in same file and re-build.
Figured that this thread is getting enough views that it's worth passing on (the limited) solution I found. Most people probably tried adding 'static' before google-ing for a solution! and I didn't see this work-around fix anywhere else.
change
public class LinqHelper
to
public static class LinqHelper
Following points need to be considered when creating an extension method:
- The class which defines an extension method must be
non-generic
,static
andnon-nested
- Every extension method must be a
static
method - The first parameter of the extension method should use the
this
keyword.