You will need to restructure the code so that you remove the circular dependency. In some cases this will involve adding a third assembly, and possibly involve adding additional types.
Consider a simple example.
Assume that in assembly ONE you had the following class
public class A
{
void Foo( B theB )
{
}
}
and in assembly TWO you had
public class B
{
A[] anArrayOfAs;
}
Clearly this makes for a circular dependency.
One solution to this problem is to introduce a new interface type in a third assembly, as follows:
Assembly ONE has
public class A : ITheAInterface
{
void Foo( ITheBInterface it )
{
}
}
In assembly TWO you might have
public class B : ITheBInterface
{
ITheAInterface[] anArray;
}
And in assembly THREE you might have
public interface ITheBInterface { ... }
public interface ITheAInterface { ... }
Note that assembly ONE is dependent only on assembly THREE. Similarly, assembly TWO is only dependent on assembly THREE.
You might be thinking that this is simply too easy, and it doesn't tackle real problems such as
(in assembly ONE)
public class A
{
void Foo()
{
B theB = new B();
}
}
and in assembly TWO
public class C
{
void Bar()
{
A theA = new A();
}
}
And you'd be right. It would appear that the third assembly option might not help because you always need the new method to create objects. Well, there's two things to consider here. The first is simply "is the code well structured?" (and to be honest, it wouldn't appear to be). The second is "if we have this level of coupling, should the components all be in the same assembly?"
Given that A, B and C seem to be unable to operate independently of each other, in this case there would be a strong argument for placing them all in one assembly.
Dave