Home All Groups Group Topic Archive Search About

Extension Methods in VB 2008 Express?

Author
21 Nov 2007 4:39 PM
dave
I can't get Extension Methods to work in Visual Basic 2008 Express.

Says "Type 'Extension' is not defined."

Looks like the library included with the Express edition is crippled.

What am I missing?

Here's the code...
Imports System.Runtime.CompilerServices
Module ExtensionMethods
    <Extension()> Public Function Test(ByVal str As String) As String
        Return str
    End Function
End Module

Author
21 Nov 2007 4:55 PM
Armin Zingler
Show quote Hide quote
"dave" <d***@discussions.microsoft.com> schrieb
> I can't get Extension Methods to work in Visual Basic 2008 Express.
>
> Says "Type 'Extension' is not defined."
>
> Looks like the library included with the Express edition is
> crippled.
>
> What am I missing?
>
> Here's the code...
> Imports System.Runtime.CompilerServices
> Module ExtensionMethods
>    <Extension()> Public Function Test(ByVal str As String) As String
>        Return str
>    End Function
> End Module

Add a reference to System.Core.dll


Armin
Author
21 Nov 2007 4:56 PM
Rory Becker
Show quote Hide quote
> I can't get Extension Methods to work in Visual Basic 2008 Express.
>
> Says "Type 'Extension' is not defined."
>
> Looks like the library included with the Express edition is crippled.
>
> What am I missing?
>
> Here's the code...
> Imports System.Runtime.CompilerServices
> Module ExtensionMethods
> <Extension()> Public Function Test(ByVal str As String) As String
> Return str
> End Function
> End Module

Are you targetting .Net 2.0, see my blog posts....
Where I thought it was a bug....
-------------------------------------------------------------
http://rorybecker.blogspot.com/2007/11/multi-target-net-20-or-extension.html
-------------------------------------------------------------
....and when I realised what was happening...
-------------------------------------------------------------
http://rorybecker.blogspot.com/2007/11/solved-multi-target-net-20-or-extension.html
-------------------------------------------------------------

Hope this helps

--
Rory
Author
21 Nov 2007 4:58 PM
Rory Becker
Alternatively you might not have added a reference to System.Core.dll to
your .Net 3.5 project

--
Rory
Author
21 Nov 2007 5:00 PM
dave
That was it.  Thank you.

Show quoteHide quote
"Rory Becker" wrote:

> Alternatively you might not have added a reference to System.Core.dll to
> your .Net 3.5 project
>
> --
> Rory
>
>
>