views:

1329

answers:

4
+1  A: 

What version of .net framework the IDE is pointing towards?

Also, at first glance the syntax of extension method looks incorrect.

The code is incomplete. Please put the using statements in the example for anyone to use the code and compile it - to reproduce the error.

shahkalpesh
It was 2.0. I had to change to 3.5 and it works.
Saif Khan
A: 

Use this...

System.Runtime.CompilerServices.ExtensionAttribute

Couldn't find anything called Extension in the namespace you mentioned.

Cyril Gupta
A: 

You should only be getting this error if one of the following are true

  1. You are not using VS 2008 - Extension Method support was added in VS2008
  2. Your code does not have a reference to System.Core.dll - Also added in VS2008

Can you check both of these? My supsicion is that you are attempting to use VS2005 to create an extension method. If this is the case, it is unfortunately not supported.

JaredPar
I am using VS 2008. When I tried to add the reference to System.Core, its greyed out (meaning its added).
Saif Khan
+1  A: 

I would add the namespace to the imports so you don't have to type it every time:

Imports System.Runtime.CompilerServices

<Extension()> _
Public Sub Test(ByVal Value As String)

End Sub

Once you have it in your imports you can just add Extension to the top of every method instead of the whole thing.

As shahkalpesh said you extension method is incomplete you will need to add the type you want to extend(see code first parm). I just had a play and found that if you don't supply a type to extend as a parameter the complier will throw an error.

Nathan W
I did, see my edit...still doesn't work.
Saif Khan
can you right click on the <extension> _ bit and go to definition?
Nathan W