0

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.

  • Possible duplicate - http://stackoverflow.com/questions/1222281/classes-residing-in-app-code-is-not-accessible/37818086#37818086 – vapcguy Jun 14 '16 at 19:37

3 Answers3

1

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.

Prashant Pimpale
  • 10,349
  • 9
  • 44
  • 84
sreejithsdev
  • 1,202
  • 12
  • 26
  • App_Code folder is already in my root folder. In my `inetpub` folder there's a folder named `painel` and inside that folder there's all my aspx pages, including `App_Code` folder. – Leandro Battochio Jan 12 '13 at 17:26
  • just open your website in VS from path .../inetpub/painel1/ and then try to compile.. – sreejithsdev Jan 12 '13 at 17:30
  • I solved it by moving the `App_Code` from `painel` directory and placing it under `wwwroot` folder along with my `web.config` file. Odd, but it works fine now. Thank you. – Leandro Battochio Jan 12 '13 at 17:34
0

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.

Sunny
  • 4,765
  • 5
  • 37
  • 72
0

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.

vapcguy
  • 7,097
  • 1
  • 56
  • 52