• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 684
  • Last Modified:

How to include the a User-Defined namespace (C#) defined in one project into the code of anopther project in VS 2003


I'm working in a ASP. NET web application that includes many different projects (using VS 2003).  As in VS 2003, each project is defined as a namespace.

Assumed that there is a project, i.e. a namespace, named NSPACE_1 in which I deifned a public class, named PCLASS_1_NS1, that in turn has a public method, named PMETHOD_1.

There is another project, i.e. namespce, named NSPACE_2. In one of the class of this namespace, there is a method where the code  needs to call the above public method PMETHOD_1.

I don't know how to include the NSPACE_1 in the code so that the public methods of this namespace is introduced to the NSPACE_2. I've tried some way like "using NSPACE_1" at the top of .cs file of the web form but the compiler complains about this.

If you've some idea about this, please help.

Thank you very much,

  • 3
  • 2
2 Solutions
have you added the NSPACE_1 namespace file to your project as a refernce if its compiled as a dll or the .cs or .vb file containing the namespace
somitsAuthor Commented:
Hi tpwells:

Thanks for your comments.
What do you mean the "NSPACE_1 namespace file"? Do you mean the .cs file of the class PCLASS_1_NS1, in which the public method PMETHOD_1 is defined?


yes, if the file is not compiled into an assembly then you will need to include the file in your project

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

somitsAuthor Commented:
Hi tpwells

How can I include the .cs file int a project.
Do I need to copy the physical file into the folder of the project? OR only adding some text into some system file of the project that indicates the path of the file?

Thanks a lot,

yes copy the file itself to your project directory and then right-click on your prject in the Solution Explorer and select "Add Existing..." then select and open the .cs file in your project directory
Hi somits

I don’t think that is the correct way to do it as you are duplicating the files.
Cause when you make changes to one file you will have to make changes everywhere you have copied the files

In our Company we do it in following way


Using NSPACE_1; for C#

Imports NSPACE_1; for vb.net

Also you have to specify the reference or else you will get following error

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

To add reference perform following steps

1      Right Click on solution in solution explorer(Ctrl + W)
2      Select Add reference
3      Browse for the Dll of Nspace_1

It’s located in the bin\Debug folder where NSPACE_1 is complied
For vs2005 generally its
f you start by selecting default option then your dll will be mostly at this location

C:\Documents and Settings\Snehal\My Documents\Visual Studio 2005\Projects\ NSPACE_1

If you are still unable to find it search for NS*.Dll

4      now make object of PCLASS_1_NS1
5      and you will be able to access the methods of that class
6      Now make the object for that class and you will get the intellence feature

Also if you make the functions static then you don’t even need make new object
Directly use the classname.functions name

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now