0

Do you know of an effective way to detect circular references between .Net assemblies?

The situation I would like to detect/prevent is such as:

  • A references B
  • B references C
  • C references A
Daniel Daranas
  • 22,454
  • 9
  • 63
  • 116
  • 8
    Visual Studio will stop you from doing this. It checks for all circular references when you attempt to add a reference. How would you end up with this situation? – Dan Herbert Mar 19 '10 at 13:18
  • 1
    You can have circular references, albeit with a bit of hassle: http://stackoverflow.com/questions/1316518/how-did-microsoft-create-assemblies-that-have-circular-references – adrianbanks Mar 19 '10 at 13:29
  • @Dan: I successfully built a solution in which A references B and B references A. I am using visual Studio 2008 Professional. – Daniel Daranas Mar 19 '10 at 13:30
  • @Henk Holterman: Actually you can, but not in the VS. – Andrew Bezzub Mar 19 '10 at 13:32
  • I just tried to repeat what you described in your question, here were my results: http://i.imgur.com/YgFky.png The situation you described is impossible on my machine. Are you adding web service references by any chance? Those references work differently and can result in indirect circular references... – Dan Herbert Mar 19 '10 at 13:38
  • @Dan: I added them navigating via the Browse tab. For one project I added the compiled result (dll) of the other one, and vice versa. – Daniel Daranas Mar 19 '10 at 13:44

1 Answers1

3

NDepend is a good tool to detect dependency cycles in your code. There is a trial version you can try out to make sure it handles the specific issue you are having.

You can check out Patrick Smacchia's blog for articles about how to use NDepend and how you can detect and visualize cycles in your code.

Steven Lyons
  • 8,138
  • 1
  • 28
  • 27