App_Code folder issues
Asked Answered
K

6

30

So I'm having a really weird issue with my App_Code folder on a new website I'm designing.

I have a basic class inside of a namespace in the App_Code folder. Everything works fine in the IDE when I setup the namespace and make an object from the class. It brings up the class summary on hover, and when you click on "go to deffinition" it goes to the class file. And it also works fine localy.

However, when I load the site onto my server, I get this error message when I access that page:

Line 10: using System.Web.UI.WebControls;
Line 11: using System.Web.UI.WebControls.WebParts;
Line 12: using xxxx.xxxx

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

I know for a fact that the class file is there. Anyone have any idea of whats going on?

Edits:

John, yes it is a 2.0 site.

Knacker answered 18/9, 2008 at 2:49 Comment(1)
How did you publish the site to the server?Put
K
67

The problem that your classes are not compiled, You'll solve this issue simply by going to the properties of any class in the App_Code folder and change it's 'Build Action' property from "Content" to "Compile"

Kinase answered 11/11, 2010 at 21:16 Comment(3)
Are there a means to change the build action of each class at once?Antitoxic
What are the ramification of doing this, is there a reason this is the default setting?Britannia
Am not able to click the property its disabledAssuan
W
22

If your application is a Web Application project rather than a Web Site project, the code files should not be in the App_Code folder (stupid design, I know). Create a new folder called code or something and put them in there.

It caused me all sorts of problems when I upgraded a bunch of old .Net web sites to application projects.

Wandis answered 18/9, 2008 at 3:23 Comment(3)
Its worth noting that if you simply drag the code files out of the App_Code folder and into your new folder, their build action property may still be set to content, and the rest of the application will not be able to see the namespaces, as one of the answers mentions below setting this to compile will sort this, I think any class file created in the App_Code folder by default will be set to build action = content, even in a WAP project.Telemotor
What a waste of time! Nothing but headaches for 6 months! Thanks for posting! +1 #26135751Kattiekatuscha
Yep, I had a web app and C# project types. mztools.com/Articles/2008/MZ2008017.aspxKattiekatuscha
B
2

This just happened to me and the solution was that App_Code (and App_Data) were not put in the root of the server, but in a subfolder that held everything else. Must be in root!

Bunch answered 29/10, 2010 at 19:26 Comment(0)
O
1

I have noticed a mismatch sometimes between the IDE parser and the compiler whenever a compile-time error occurs in a referenced assembly or code file. In that circumstance the IDE will correctly identify the types and provide full support for them, but since the compiler was unable to create the referenced objects, it will complain that the referenced objects don't exist.

Now I don't want to go accusing anybody of anything—this is just a guess—but you should probably make sure there are not any errors in your referenced code file.

Op answered 18/9, 2008 at 3:53 Comment(0)
S
1

Depending on how you publish the site, it won't look in App_Code, it'll look for a DLL in the Bin folder that contains the class instead. How did you transfer your website to the server?

Scutiform answered 4/10, 2008 at 21:53 Comment(0)
G
0

For those that follow...I had this same set of issues but it was caused because I named a class in App_Code, 'HTML'. Took a long while to figure out that it was just a name conflict because the compiler wasn't being very helpful about telling me what the problem was.

Geminius answered 27/5, 2015 at 15:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.