Leandro Battochio
Leandro Battochio

Reputation: 364

Class in App_Code not accessible

I have a Config.cs file inside the App_Code folder:

namespace C
{
public class Config
{
  ......
 }
 }

In my default.aspx.cs page, I added using C; but I can't load the page. It says:

CS0246: The type or namespace name 'C' could not be found (are you missing a using directive or an assembly reference?)

I'm using CodeFile instead of CodeBehind and I already tried to set the Build Action property to Compile but I cant find that option in the class properties page. I am using VS 2012.

It works fine though when I press F5 in VS 2012 and access my site under that port. It only show error when I try to access my page directly, as any other user would try to.

Upvotes: 0

Views: 6375

Answers (3)

sreejithsdev
sreejithsdev

Reputation: 1210

I think your App_Code folder is not in root folder of project. Please make sure that you have put App_code folder in project path which contains default.aspx file. Don't keep App_code within a nested folder.

Upvotes: 1

vapcguy
vapcguy

Reputation: 7545

You should just edit the Properties of the class files in Visual Studio and mark the Build Action as "Compile", instead of "Content", then rebuild and re-publish your project.

Upvotes: 0

Sunny
Sunny

Reputation: 4809

Try to pre-compile the application and publish on server. If it is not precompiled, make sure the class file exists in server 'App_Code' folder. When the application receives first request, this class gets compiled.

Upvotes: 0

Related Questions