Can't access my class from code-behind. Class is App_Code folder

webworm picture webworm · Feb 15, 2011 · Viewed 13.1k times · Source

I have a very simple class that is located within my App_Code folder in my VS2008 web application project. I am trying to instantiate an instance of this class from my code-behind file. Intellisense does not seem to be seeing my class and I am not sure why. I am using VB.NET which I am admittedly not that familiar with as compared to C#. Perhaps I am missing something. I would bet it has something to do with something I am missing in VB.NET.

Here is my simple class (for testing):

Public Class mySimpleClass

   'Private member variables whose data is obtained from user input
    Private mUserID as String

   'Class Properties
    Public Property UserID() as Integer
       Get
          Return mUserID
       End Get

       Set(ByVal Value as Integer)
          mUserID = Value
       End Set
    End Property

    'Class Methods
    Public Function DisplayUserID() as String
       Return this.UserID
    End Function

End Class

Here is how I try an instantiate it from the codebehind ...

Partial Public Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim obj As New mySimpleClass()
    End Sub

End Class

Answer

webworm picture webworm · Feb 15, 2011

What I ended up doing was deleting my App_Code folder and creating a new "AppCode" folder. I also selected properties for the class file and set the Build Action property to "Compile". Once I did that and recompiled the project my class showed up.