We help IT Professionals succeed at work.

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

somits
somits asked
on
Medium Priority
720 Views
Last Modified: 2008-01-09
Hi:

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,

Somits
Comment
Watch Question

Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

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?

Thanks,

Somits

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

Author

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,

Somits

Commented:
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
Commented:
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

Type

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

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
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.