By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,238 Members | 1,787 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,238 IT Pros & Developers. It's quick & easy.

Circular reference

P: n/a
Hi

I Have a solution with about 50 projects and each project have References to
1 to n of the projects in the solution. I try go to a project and try to add
a reference to another project and I get a Circular Reference" error and
cannot reference the project.

Is there any way to find out the what Method or Project is causing the problem
If I am on Project A tring to add Project B - I checked that A doesn't
include B and B doesn't include A - it must be some other project that is
referenced and calling someone else.

Just looking for a suggestion to track down the culprit :-)
Thanks

Mar 28 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
It is actually pretty easy to list the entire reference tree for an
assembly, either through reflection (if compiled) or through parsing
the csproj files (if not). I have samples of both, but they are tied
into other code that I don't want to have to remove - but you may find
this useful for pulling it apart. Note that you need to be a little
careful : the 2 core MS libs at the bottom are themselves circular, so
you need to check against that when enumerating.

Get an Assembly either from a known Type or from the startup Assembly.
From an Assembly you can use GetReferencedAssemblies() to get the
references, which you can then attempt to load via the static
Assembly.Load method (which IIRC returns the existing Assembly if it
is already loaded) - but note that this can throw an exception if the
necessary reference isn't found.

I would probably just use the above to output the tree of your problem
assembly (where you can't add the reference), which should quickly
reveal why... no more that 20 minutes coding I'd guess.

Marc
Mar 28 '07 #2

P: n/a
Hi,
According to your description, I understand you want know how to track down
the "Circular Reference" error.

For example: we have three Projects: ProjectA, ProjectB, ProjectC.
ProjectA has a reference to ProjectB, (ProjectA->ProjectB)
ProjectB has a reference to ProjectC. (ProjectB->ProjectC)
When we are on ProjectC trying to add referece to ProjectB, we will receive
an error massage "Circular Reference". (Because ProjectB has a reference to
ProjectC)
Additionally, if we are going to add referece to ProjectA, we will also
receive the same error meassage "Circular Reference".
(ProjectA->ProjectB->ProjectC).

Apparently, I think the second scenario is similar to your solution.
To trouble down such issue, as Marc said, add some code to draw a
dependence tree of your project.
Another choice, you may use the feature "Project References" in Visual
Studio 2005 IDE.
Right Click your Project, Select "Project dependences..." option in context
menu.
If there is a Circular Reference between two projects, there must have the
same project entry in Project dependences dialog.
In this scenario, it is ProjectB.

By the way, I think "Reflector" is also a good option. Thanks for Marc's
suggestion.:)

Hope this helps. If you have anything unclear, please feel free to update
here and I'm glad to assist you.

Have a great day,
Sincerely,
Wen Yuan
Microsoft Online Community Support
===============================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
===============================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Mar 28 '07 #3

P: n/a
The best tool to find circular references not only bewteen assemblies but
also between namespaces or types or methods is NDepend
http://www.NDepend.com

Have a glance at this 4mn demo:
http://s3.amazonaws.com/NDependOnlin...ewlet_swf.html

Patrick
"Marc Gravell" <ma**********@gmail.coma écrit dans le message de news:
uY**************@TK2MSFTNGP04.phx.gbl...
It is actually pretty easy to list the entire reference tree for an
assembly, either through reflection (if compiled) or through parsing the
csproj files (if not). I have samples of both, but they are tied into
other code that I don't want to have to remove - but you may find this
useful for pulling it apart. Note that you need to be a little careful :
the 2 core MS libs at the bottom are themselves circular, so you need to
check against that when enumerating.

Get an Assembly either from a known Type or from the startup Assembly.
From an Assembly you can use GetReferencedAssemblies() to get the
references, which you can then attempt to load via the static
Assembly.Load method (which IIRC returns the existing Assembly if it is
already loaded) - but note that this can throw an exception if the
necessary reference isn't found.

I would probably just use the above to output the tree of your problem
assembly (where you can't add the reference), which should quickly reveal
why... no more that 20 minutes coding I'd guess.

Marc

May 6 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.