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

13,401

Solution 1

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.

Solution 2

  1. you should change Return this.UserID to Return Me.UserID (VB.Net ;-))
  2. rebuild the solution and see if it works

I'm not as familiar with the app_code folder and Websites in general, i'm always using WebApplications. I would suggest to convert it to a WebApplication too, here are further informations why: ASP.NET Web Site or ASP.NET Web Application?

Solution 3

Actually, I think if you add namespace to your project, it should work as well. I seem to remember having that problem every so often in C# asp.net as well. I could be way wrong though

Share:
13,401
webworm
Author by

webworm

Updated on June 07, 2022

Comments

  • webworm
    webworm almost 2 years

    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