Classes residing in App_Code is not accessible
I have created a website in ASP.NET and have created a class and put it inside of the App_Code folder. However I cannot access this from my other pages. Does something need to be configured to allow this? I have made it work in previous projects, but not in this one, somehow.
namespace CLIck10.App_Code
{
public static class Glob
{
...
}
}
Solution 1:
Right click on the .cs
file in the App_Code
folder and check its properties.
Make sure the "Build Action" is set to "Compile".
Solution 2:
Put this at the top of the other files where you want to access the class:
using CLIck10.App_Code;
OR access the class from other files like this:
CLIck10.App_Code.Glob
Not sure if that's your issue or not but if you were new to C# then this is an easy one to get tripped up on.
Update: I recently found that if I add an App_Code folder to a project, then I must close/reopen Visual Studio for it to properly recognize this "special" folder.
Solution 3:
Go to the page from where you want to access the App_code class, and then add the namespace of the app_code class. You need to provide a using
statement, as follows:
using WebApplication3.App_Code;
After that, you will need to go to the app_code class property and set the 'Build Action' to 'Compile'.