| | |
Cannot access a project's namespace in a solution
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
i am developing a visual studio solution that contains two projects.
Each project has its own namespace :
Project1 : namespace MainProject.Project1
Project2 : namespace MainProject.Project2
My problem is that i cannot access 2nd project's namespace in the 1st project and vice versa.
I tried to add the namespace through "using" statement :
But, surprisingly, in Project1, the IntelliSense didnt even show me the Project2 namespace. Same was the case when i checked the other way round.
I think they should be accessible from each other because they are nested within the root namespace MainProject.
How do i solve this?
Each project has its own namespace :
Project1 : namespace MainProject.Project1
Project2 : namespace MainProject.Project2
My problem is that i cannot access 2nd project's namespace in the 1st project and vice versa.
I tried to add the namespace through "using" statement :
C# Syntax (Toggle Plain Text)
using namespace MainProject.Project2;
But, surprisingly, in Project1, the IntelliSense didnt even show me the Project2 namespace. Same was the case when i checked the other way round.
I think they should be accessible from each other because they are nested within the root namespace MainProject.
How do i solve this?
Bhoot
No, they shouldn't. You should add reference from Project1 to Project2 to be able to write
using namespace MainProject.Project2; To add reference, from Project1 solution explorer references->add reference->browse to locate the project2 assembly or projects tab to get all assembles in all solution including project2 assembly. BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
•
•
•
•
No, they shouldn't. You should add reference from Project1 to Project2 to be able to write using namespace MainProject.Project2; To add reference, from Project1 solution explorer references->add reference->browse to locate the project2 assembly or projects tab to get all assembles in all solution including project2 assembly. But then its not letting me add references to both the projects saying that it would create a circular dependency.
How do i deal with that?
Bhoot
Yes, Just add reference from one to another not from both to both.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
The problem is both projects can't access one another. There is a compile order you can see (click the "Debug"/"Release" dropdown and select options at the bottom, its in there). It first compiles project A, then project B. But if it cannot compile Project A until Project B has been compiled, and Project B cannot be compiled until Project A has been compiled... you have circular dependencies.
All of the code that is common between the two assemblies must be moved to a third assembly, and your two existing projects can reference that assembly.
Also -- Be sure that when you add a reference for a project in the same solution that you click "Add Reference..." and at the top you will see tabs, click the "Projects" tab and add a reference to the project by name, not to the C:\location\of\the\dll.
All of the code that is common between the two assemblies must be moved to a third assembly, and your two existing projects can reference that assembly.
Also -- Be sure that when you add a reference for a project in the same solution that you click "Add Reference..." and at the top you will see tabs, click the "Projects" tab and add a reference to the project by name, not to the C:\location\of\the\dll.
•
•
•
•
The problem is both projects can't access one another. There is a compile order you can see (click the "Debug"/"Release" dropdown and select options at the bottom, its in there). It first compiles project A, then project B. But if it cannot compile Project A until Project B has been compiled, and Project B cannot be compiled until Project A has been compiled... you have circular dependencies.
All of the code that is common between the two assemblies must be moved to a third assembly, and your two existing projects can reference that assembly.
Also -- Be sure that when you add a reference for a project in the same solution that you click "Add Reference..." and at the top you will see tabs, click the "Projects" tab and add a reference to the project by name, not to the C:\location\of\the\dll.
ohk..i got it.
i will implement what you said. Infact , that would make my project easier to handle.

But, then wouldnt it affect the namespaces i have already structured?
Or just refactoring the namespaces and changing the default namespace in the projects would work out?
Also then my structure would be as follows :
C# Syntax (Toggle Plain Text)
namespace NetworkTracker { // types common to both the other assemblies (or projects). // i would create this in a project named NetworkTrackerCommon. namespace Tracker { // client-side code // i will include this namespace in client-side assembly : Tracker } namespace UserInterface { // server-side code // i would include this namespace in server-side assembly : UserInterface } }
What should i keep the default namespaces in each of the assemblies ?
I think it should be :
NetworkTracker in NetworkTrackerCommon assembly
NetworkTracker.Tracker in Tracker assembly
NetworkTracker.UserInterface assembly
I would also refactor the names in their respective assemblies.
Am i right? Or i should keep the root namespace NetworkTracker as the default namespace in all of the projects ? ( i didnt seem this feasible).
Bhoot
As far as moving code around, just refactor it like you mentioned. I don't see why you would having a nested namespace like you posted, though. And as far as mentioning what code goes in what assembly I couldn't tell you without knowing your project a little better. Here is an example of a project I have that includes an ASP.NET website and a .NET Windows form application that share a common BLL (business logic) and DAL (data access).
I hope that makes sense and helps in your decision making. If you still have questions then post the function of each assembly you have, or think you should have, and we'll go from there.
C# Syntax (Toggle Plain Text)
Project.Web - Website (refs .core, .data, .extensions, .merchants) Project.Core - BLL (refs .data, .desktop, .merchants, .extensions) Project.Data - DAL (refs .extensions) Project.Desktop - .NET Form App (refs .core, .data. .extensions) Project.Extensions - 3.5 Extensions (no refs) Project.Merchants - Online merchant stuff (refs .extensions)
I hope that makes sense and helps in your decision making. If you still have questions then post the function of each assembly you have, or think you should have, and we'll go from there.
•
•
•
•
As far as moving code around, just refactor it like you mentioned. I don't see why you would having a nested namespace like you posted, though. And as far as mentioning what code goes in what assembly I couldn't tell you without knowing your project a little better. Here is an example of a project I have that includes an ASP.NET website and a .NET Windows form application that share a common BLL (business logic) and DAL (data access).
C# Syntax (Toggle Plain Text)
Project.Web - Website (refs .core, .data, .extensions, .merchants) Project.Core - BLL (refs .data, .desktop, .merchants, .extensions) Project.Data - DAL (refs .extensions) Project.Desktop - .NET Form App (refs .core, .data. .extensions) Project.Extensions - 3.5 Extensions (no refs) Project.Merchants - Online merchant stuff (refs .extensions)
I hope that makes sense and helps in your decision making. If you still have questions then post the function of each assembly you have, or think you should have, and we'll go from there.
you are right.I wont make a nested namespace.
I will go as follows :
NetworkTracker.Common - the assembly containing the common code.
NetworkTracker.Tracker namespace for the client-side assembly.
NetworkTracker.UserInterface namespace for the server-side assembly.
thank you.
Bhoot
![]() |
Similar Threads
- not able to access VSS folder from Visual Studio 2003 (ASP.NET)
- How to add an existing form in the other project (C#)
- Help! I can't access my own folders & files! (Windows NT / 2000 / XP)
- Microsoft Access date validation Need a solution (Database Design)
- Need to find a solution similar to Yahoo News related search (JavaScript / DHTML / AJAX)
- Win32 API Struct (Perl)
- MS Access Project (MS Access and FileMaker Pro)
- IE won't let me access threads. Could someone email me a solution please? (Web Browsers)
Other Threads in the C# Forum
- Previous Thread: How to open a excel file.
- Next Thread: Processing client messages
| Thread Tools | Search this Thread |
.net access algorithm array asp barchart bitmap box broadcast buttons c# check checkbox client column combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development display draganddrop drawing encryption enum equation event excel file form format formbox forms formupdate function gdi+ httpwebrequest image index input install java label linux list listbox mandelbrot math mouseclick mysql networking operator packaging parse path photoshop picturebox pixelinversion post powerpacks programming radians regex remote remoting reporting richtextbox robot server sleep socket sql statistics stream string table text textbox thread time timer transform treeview update usercontrol validation visualstudio webbrowser wfa windows winforms wpf xml






