943,733 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 3334
  • C# RSS
May 10th, 2009
0

Cannot access a project's namespace in a solution

Expand Post »
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 :

C# Syntax (Toggle Plain Text)
  1. 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?
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
Bhoot is offline Offline
53 posts
since Oct 2008
May 10th, 2009
0

Re: Cannot access a project's namespace in a solution

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.
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006
May 10th, 2009
0

Re: Cannot access a project's namespace in a solution

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.
yaa..i tried that out.
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?
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
Bhoot is offline Offline
53 posts
since Oct 2008
May 10th, 2009
0

Re: Cannot access a project's namespace in a solution

Yes, Just add reference from one to another not from both to both.
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006
May 11th, 2009
0

Re: Cannot access a project's namespace in a solution

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.
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
May 11th, 2009
0

Re: Cannot access a project's namespace in a solution

Click to Expand / Collapse  Quote originally posted by sknake ...
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)
  1. namespace NetworkTracker
  2. {
  3. // types common to both the other assemblies (or projects).
  4. // i would create this in a project named NetworkTrackerCommon.
  5.  
  6. namespace Tracker
  7. {
  8. // client-side code
  9. // i will include this namespace in client-side assembly : Tracker
  10.  
  11. }
  12.  
  13. namespace UserInterface
  14. {
  15. // server-side code
  16. // i would include this namespace in server-side assembly : UserInterface
  17. }
  18. }

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).
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
Bhoot is offline Offline
53 posts
since Oct 2008
May 11th, 2009
0

Re: Cannot access a project's namespace in a solution

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)
  1. Project.Web - Website (refs .core, .data, .extensions, .merchants)
  2. Project.Core - BLL (refs .data, .desktop, .merchants, .extensions)
  3. Project.Data - DAL (refs .extensions)
  4. Project.Desktop - .NET Form App (refs .core, .data. .extensions)
  5. Project.Extensions - 3.5 Extensions (no refs)
  6. 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.
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
May 11th, 2009
0

Re: Cannot access a project's namespace in a solution

Click to Expand / Collapse  Quote originally posted by sknake ...
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)
  1. Project.Web - Website (refs .core, .data, .extensions, .merchants)
  2. Project.Core - BLL (refs .data, .desktop, .merchants, .extensions)
  3. Project.Data - DAL (refs .extensions)
  4. Project.Desktop - .NET Form App (refs .core, .data. .extensions)
  5. Project.Extensions - 3.5 Extensions (no refs)
  6. 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.
yaaa...i got it.
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.
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
Bhoot is offline Offline
53 posts
since Oct 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: How to open a excel file.
Next Thread in C# Forum Timeline: Processing client messages





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC