Solved

Class not found in ASP.NET project

Posted on 2008-09-29
5
510 Views
Last Modified: 2013-12-17
Please forgive me, I'm new to C#.

I have added a class file to my ASP.NET project but I cannot reference it as a type in my default.aspx code behind.  

I've put test classes at the root of the project and in folders under App_Code.  All the types I try to declare error out on compile.

What steps do I need to take after creating a class file to be able to reference that class in the rest of my app?

0
Comment
Question by:Bruce
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 16

Assisted Solution

by:CuteBug
CuteBug earned 50 total points
ID: 22597361
You need to add a reference of the dll to which this class belongs.
0
 
LVL 14

Accepted Solution

by:
CyrexCore2k earned 450 total points
ID: 22597372
Look at your classes and note their namespace in relation to the namespace of your default.aspx page class. It's probably going to be something like

namespace xxxxYourProjectNamexxxx.App_Code // for the classes
namespace xxxxYourProjectNamexxxx // for the page

So to reference an class from your page you're going to either have to write

App_Code.MyClass

or add a using statement:

using xxxxYourProjectNamexxxx.App_Code;

to the top of your code behind file
0
 
LVL 1

Author Comment

by:Bruce
ID: 22597435
My new class is not within a namespace.  The class I am tying to reference is actually imported from another project where it was being used without a namespace declaration.

Is this a case of I have to either "Add Reference" to a DLL or wrap the class within a namespace in order to be referenced?  

If I do the "Add Reference" on a class that exists only within my project where do I find the DLL on my file structure in order to reference it.
0
 
LVL 1

Author Comment

by:Bruce
ID: 22597662
I added the namespace to my class at the root of the project and that gets referenced.  But the class that is in my App_Code directory is still not showing.  The specific location of the class file I am trying to reference is ~/App_Code/Common/ActiveDirectoryHelper.cs.

I have tried wrapping these namespaces around the ActiveDirectoryHelper class declaration
AppSurvey_PType
AppSurvey_PType.App_Code
AppSurvey_PType.App_Code.Common

After each I tried a rebuild and then tried to dot operate off the AppSurvey_PType namespace but App_Code does not show under there...

Is this where I need to somehow build a DLL for the class file and reference it or can I still try to use namespace to reference it?

0
 
LVL 1

Author Comment

by:Bruce
ID: 22599682
This was a tough one so I just started a new Web Project in Visual Studio.  There was something not set right on the "solution" because when I tried to add Web Forms it would not show the options for selecting a master page.

I've added the my existing file from the other project, then added the namespace in those class files and they all show up when I dot operate in the code behind.

Thanks for you help!  I don't know what is different between the projects but starting a new one and adding my work back in was the workaround.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question