Question

I have a solution with two projects inside. Say Project A and Project B. In the first project I have:

namespace MySolution.ProjectA {
  public class ClassA { /* Referencing something in  MySolution.ProjectB ns */ }
}

In the other project I have:

namespace MySolution.ProjectB {
  public class ClassB { /* Referencing something in  MySolution.ProjectA ns */ }
}

ClassA uses ClassB. So Project A references Project B.

In ClassB I need to use ClassA, so I need to reference Project A from Project B but can't because a circular reference would occur. How to handle this?

One thing to say...

I know that this condition means that something in the application design was not correct, but I need to do this to inspect a legacy application.

Was it helpful?

Solution

A circular reference can never be, so what you do, is take out the thing you need to reference from Project B in Project A and put it into Project C.

Project A & B can then reference C but C doesn't reference A or B.

OTHER TIPS

I encountered a similar scenario in the past. There were two strategies that were used:

  1. Have one project reference a compiled version of the other project. ProjectA reference ProjectB and projectB references ProjectA.dll.
  2. Have the project with 'ClassA' include a reference to the class file of 'ClassB' and not the project.

All roads lead to ugliness, but this can work for debugging.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top