3

I have a number of extension methods defined in my current project. It is a VB.NET project. I have no problem using these methods inside files that are in the App_Code directory, this is the same place that I defined the methods. However, in my page.aspx.vb code behind page these methods are not showing up. I have tried including the correct namespace, with no luck.

Does anyone have an idea as to why I can't call an extension method in a code behind file?

Defined in the App_Code folder

<Extension()> _
Public Function GetSelected(ByVal apps As List(Of Appointment)) As Appointment
    Dim selected = From a In apps _
                   Where a.Selected = True

    Return selected.Single
End Function

Defined in the App_Code folder, inside another class(this one works just fine)

Public ReadOnly Property Selected() As Appointment
    Get
        Return _appointments.GetSelected()
    End Get
End Property

Defined in the App Root folder, inside a code behind file(Not working)

Public ReadOnly Property Selected() As Appointment
    Get
        Return _appointments.GetSelected()
    End Get
End Property

They are all in the same application, no external references. And When I build the project there are no errors, until I try to use the extension method in the code behind. At that point the error is 'GetSelected' is not a member of 'System.Collections.Generic.List(Of Appointment)'

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
zznq
  • 400
  • 1
  • 15
  • Do you have an example of a declaration of one of these methods, as well as how you are trying to use them? – Brian Mar 11 '09 at 18:49

4 Answers4

10

Make sure your module is marked Public.

BC.
  • 24,298
  • 12
  • 47
  • 62
1

Try to call the methods "normally" - i.e. as if they were standard shared methods. If you can do so without fully qualifying the type with the namespace, something very odd is going on. Can you use any other VB9 features?

If you can only call it by fully qualifying the type, then it's an Imports issue.

If you can't call it at all, it's a reference issue - but I'm afraid I've had problems with App_Code myself before now in ASP.NET, and basically don't have enough ASP.NET mojo to help any further. Hopefully answering these questions should help someone who is competent to help you more though :)

EDIT: Okay, so you can't use any VB9 features (try something other than LINQ to be certain) and you can't access a shared method from the App_Code directory. Do you have colleagues with Visual Studio? Can you try it on their machines? It sounds like something's very wrong with your installation.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • No sorry, I am think I am slowly adding clarity to my question. – zznq Mar 11 '09 at 19:27
  • Okay, I've removed that edit. Have you tried calling the method directly yet, i.e. WhateverTypeName.GetSelected(_appointments) – Jon Skeet Mar 11 '09 at 19:44
  • Yes, I tried calling it like it was a shared method, it was not there. But no I can't use any of the other VB9 features(specifically LINQ is what I tried). That is odd. – zznq Mar 11 '09 at 19:57
  • I had a colleague look a my code. I didn't mark my module as public. Thanks you the help. – zznq Mar 12 '09 at 18:01
0

Did you try to reference the assemblies where they are? Also, build your project and try to guessed what is wrong from the errors messages. You may put some of them here, too.

cjk
  • 45,739
  • 9
  • 81
  • 112
eKek0
  • 23,005
  • 25
  • 91
  • 119
0

Have you tried closing and reopening VS?

cjk
  • 45,739
  • 9
  • 81
  • 112