.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Why does a class in the App_Code folder get ignored by the compiler?

Posted By:      Posted Date: October 05, 2010    Points: 0   Category :ASP.Net


I've noticed that with some, but not all sites, if I add a class in a .cs file in the App_Code folder, then I can't reference the class anywhere. In some sites, this isn't a problem. If I move the .cs file to the root, then no problem.

Anyone able to explain what's going on here? I have a mixture of sites created in VS2010, along with ones that existed before I got it. Don't know if this makes any difference.

More to the point, how do I persuade VS2010 (and I suppose IIS ultimately) to allow .cs files in App_Code, as I find this much neater than having class files littered around the root.


View Complete Post

More Related Resource Links

Classes created inside App_Code dir is ignored by the compiler



I have the following problem programming in asp .net with visual studio 2008. If I insert a new class file, right clicking on "add new element -> class -> ecc..." directly inside the App_Code directory (or in its any subdirectory) the compiler and the smartTab do not see any custom namespace previously created in other classes, nor from other classes I can find the namespace and the class name defined within the new class file just inserted. The only way I found to correctly insert a new class file is create it right clicking on "add new element... ecc..." not in the App_Code (or sub) directory but rather in the root node with the name of the entire project, and then I can move it in the destination App_Code subdirectory, and it keeps working.

As a matter of facts it seems that is not important where the file IS but rather where I CREATED it: if I created a class from inside the App_Code it does not see anything and it is not seen by any other class, otherwise if I create it right clicking on the root node of the project it works and keeps workng even moving inside any subdir within the project.

I also tried to manually add the App_Code subdirs to the <Compilation> and <codeSubDirectories> tags of the Web.config file, but anything changed with this behaviour.

Does anybody know why?


LINQ to SQL compiler error CS1519: Invalid token 'void' in class, struct, or interface member decl

I get the following compiler errors when creating my first LINQ to SQL class (I just dragged a table "ProfileExtended" onto the designer and hit build):DataClasses.designer.cs(31,11): error CS1519: Invalid token 'void' in class, struct, or interface member declaration these are the offending lines of autogenerated code:#region Extensibility Method Definitions  partial void OnCreated();  partial void InsertProfileExtended(ProfileExtended instance);  partial void UpdateProfileExtended(ProfileExtended instance);  partial void DeleteProfileExtended(ProfileExtended instance);  #endregion

Can't debug classes in App_Code folder

I've gone through the forum and I've googled this issue and I'm surprised by how little information I've found.  I recently converted my ASP.NET 1.x project to ASP.NET 2 and I've found that while debugging I cannot step into code stored in the App_code folder.  This is a serious problem for me as something is broken and I can't discover the source without my trusty debugger.  Please, does anyone have a resolution for this issue.  I understand that it is related to the fact that the App_Code folder is compiled dynamically but surely there must be some way of debugging the classes in there :-( I have debug="true" in my config file, all my projects are building in the Debug configuration.  Breakpoints in the aspx files work fine, but then any code reference to a class in App_Code is stepped over by the debugger. Thanks very much for your help.

can the App_Code folder of a project contain both C# and VB# classes (in 1 proj)

Using vb.net/asp.net 2005.I have a project that is done with all vb.net, however I want to get some more experience with C#.Net.I am considering creating a new database class to put in the app_code folder, I am thinking that this is allowable and will work but just wanted to check to see if anyone else has tried something similar. thanks

App_Code Folder



I have created a C# Web Site in Visual Studio 2008 with an App_Code Folder that contains 2 classes.

Both classes have their namespace set to App_Code and my aspx.cs files include the reference to App_Code.

When I run the app from VS the site compiles and runs fine but when I try to run it from my Windows 7's IIS install I get an error that it cannot find the App_Code Namespace.

I did find a solution here: http://forums.asp.net/p/1181651/3945778.aspx but it does not seem to work in VS2008.

I someone has seen this issue and can direct me to a solution that would be great.

Let me know if I should be for detailed


can't create new mdf file in App_Code folder


I just installed vwd express 2008 and SSE 2008.  For SSE i setup a default installation (i.e. SQLEXPRESS as the default instance name etc). 

In VWD when i right-click on the "App_Data" folder and select "Add New Item--->SQL Server Database" i get the following message:

"  Connections to SQL Server files (*.mdf) require SQL Server Express 2005 to function properly.  Please verify the installation of the component or download from the URL: ............."

So to get around that what i've done is select the "Database Explorer" tab and right-click on "Connections--->Add Connection".  This process works for me but the other doesn't.  Any idea why?

One problem with the 2nd approach is now that database appears in the database explorer for any project i have open in VWD.  Again any idea why thats happening?

 If anyone could offer a suggestion as to why i can't add a new connection in the solution explorer as explained above that would be fantastic.

 Also - i don't know if it matters but i'm running a 64-bit version of vista and have installed the x64 version of SSE.



Import class from App_Code to aspx page - how?



I have class file in my App_Code called "engine.vb".


No I want to use somewhere in my page.aspx file, function which is in this file. How to import this class?

Imports Namespace="engine" doesn't work, I also didn't find anything which could help me.



Intellisense / class reference not working in MembershipProvider derived class file in App_Code fold



I am new to ASP.NET and may be biting off more than I can chew, but I figure if I jump in the deep end I may learn more.

Can somebody tell me why the Visual Studio intellisense is not working in a newly created class file inside the App_Code folder?

I presume that System.Web is not being referenced from the App_Code folder correctly for some reason, because as soon as I type "using System.Web", everything is fine and then stops when I want to add ".Security" (no dropdown). I think this has an influence on the fact that the inherited MembershipProvider in my code is not highlighted/referenced and I cannot use the "Implement Abstract Class" option.

If I create a new class file in the root folder of my website, everything works fine. I have even tried to delete and recreate the file in my App_Code and it still did not work. I also tried to copy the file from my App_Code folder to the root and it still did not work. My code is as follows:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;

namespace PodcastManager
    public class

Call each class in folder


Hi all,

I'm developing an application that needs to be very easily maintained. Currently, the program calls a boolean function, which determines if a given set of criteria are met, and then if true... increments a counter.  Afterwards, it moves on to the next function, until all 9 funcitons have been called and the counter now set anywhere between 0-8.

I would like to put each function in a class file, within a subfolder.  IE:  Main Application -> Service1.asmx -> DataCriteria (folder) -> OverLimit, UnitExpired, AddressUnavailable, etc. etc. etc.

Then, have a method (using reflection or whatever means possible) that will loop through each .vb (class) file in the DataCriteria folder, and run its Main function to get the boolean.  This would mean that the calling application does not care how many classes exist in that folder, it checks each class.  And if new criteria needs to be added, i just create a new class and plop it into that folder, without having to edit any code files.

Of course, each class within the DataCriteria folder would need to implement an interface, to verify that they each have the same method type...

any ideas / suggestions?


Can't access App_Code class in Code Behind file


I have a class defined in the App_Code subdirectory:

namespace WebApplication9_App_Code
  public class Class1

And I have a code behind class default.aspx.cs:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace WebApplication9
  public partial class _Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
      WebApplication9_App_Code.Class1 cls1;

I get the following compilation error:

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

What am I doing wrong? 

Thanks very much for your help.

Files in App_Code folder unavailable in VS2010



I am stuck and unable to continue with my project.

I have...

.NET 4.0
Vista 64bit
Web Project

I created an App_Code folder and placed code modules/classes into it... BUT now I am unable to get to any of the files and the directory is NOT showing up in the intelisense.

I have tried...

Using Suma2.App_Code;  -  FAILED
Suma2.App_Code SAC = new Suma2.App_Code;  -  FAILED

Gor any suggestions or thoughts?



Class Diagrams

Class diagrams show the static structure of the systems. Classes define the properties of the objects which belong to them. These include:

Attributes - (second container) the data properties of the classes including type, default value and constraints.

Creating a Simple Class in C#

The second article in the C# Object-Oriented Programming tutorial describes how classes are created in C# and how behaviour, in the form of publicly visible and private, hidden methods can be added. This demonstrates some of the uses of encapsulation

Static Class for Beginners

In general, the members of a class can be accessed by instance of that class when they are in public, but there comes a situation to access or call members of a class without an instance and this can be achieved by declaring them as static

Compiler-generated scopes for local variable declarations

I was tasked with understanding and fixing a bug on error reporting with foreach iteration variables the other day, and it got me thinking about local variable scoping rules in C# in general. First, the bug.

abstract away the source of the connection string using a class with a static property.

ASP.NET provides a configuration system we can use to keep our applications flexible at runtime. In this article we will examine some tips and best practices for using the configuration system for the best results.

The element of a web.config file is a place to store connection strings, server names, file paths, and other miscellaneous settings needed by an application to perform work. The items inside appSettings are items that need to be configurable depending upon the environment, for instance, any database connection strings will change as you move your application from a testing and staging server into production.

Let's abstract away the source of the connection string using a class with a static property.

MessageQueue Class

This sample demonstrates two way communications using message queuing between a device application and a desktop application. One application sends book order messages to a message queue and another application receives these book orders from the message queue and responds to the device queue that the orders have been processed.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend