473,320 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Circular reference

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
3 3720
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Vera | last post by:
I have two assemblies that each consist of several classes. Each object instantiated from those classes can have one or more child- and/or parentobjects that are also instantiated from those...
2
by: Earth Worm Jim | last post by:
I have been able to get simple circular references to be serialized in xml by using the ImportTypeMapping method on the SoapReflectionImporter class. But I am unable to serialise circular...
11
by: Steve Jorgensen | last post by:
I just came up with a really tidy little solution to the VB/VBA circular reference issue. It only works with Access 2000 or newer, but that's about the only down-side. The issue... You need an...
6
by: T Koster | last post by:
After a few years of programming C, I had come to believe that I finally knew how to correctly organise my structure definitions in header files for mutually dependent structures, but I find myself...
12
by: Frank Rizzo | last post by:
I have a circular reference between 2 classes in the same project (i.e. each class refers to the other). The app runs fine and I am seeing no issues, which kind of surprised me. Are there any...
6
by: Stephen Robertson | last post by:
We are currently in a dead end with a circular reference issue using vb.net, and are hoping someone might help us resolve it. Idea... We have frmmain calling frmperson (dim f as new frmperson)...
3
by: Solution Seeker | last post by:
Hi All, I am here with a Query and need a Solution for it. The Query is as Follows, We have 3 Projects in a Solution - Say UI, CMN and PRD First One Deals with UI Forms Second One Deals...
8
by: nyhetsgrupper | last post by:
I have written a windows service and want to expose a web based user interface for this service. I then wrote a class library containing a ..net remoting server. The class library have a method...
3
by: =?Utf-8?B?UGF1bCBIYWxl?= | last post by:
Moving all User Controls to a single directory has solved my problem - Thanks Eliyahu. That said, I still got one Circular ref error yesterday, rebuilt again and the build was fine? Far far...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.