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

Posted on 2006-03-25
Last Modified: 2008-01-09

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,

Question by:somits
    LVL 10

    Assisted Solution

    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

    Author Comment

    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?


    LVL 10

    Expert Comment

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

    Author Comment

    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,

    LVL 10

    Expert Comment

    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
    LVL 3

    Accepted Solution

    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

    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

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity mvc - Time 37 45
    Contant UI messages in .NET 1 22
    Deal with Nullable Strings in ASP.NET VB.NET 5 28
    varchar (max) 5 22
    AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video discusses moving either the default database or any database to a new volume.

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now