Search code examples
.netassembliescircular-referencebase-class-library

How did Microsoft create assemblies that have circular references?


In the .NET BCL there are circular references between:

  • System.dll and System.Xml.dll
  • System.dll and System.Configuration.dll
  • System.Xml.dll and System.Configuration.dll

Here's a screenshot from .NET Reflector that shows what I mean:

enter image description here

How Microsoft created these assemblies is a mystery to me. Is a special compilation process required to allow this? I imagine something interesting is going on here.


Solution

  • I can only tell how the Mono Project does this. The theorem is quite simple, though it gives a code mess.

    They first compile System.Configuration.dll, without the part needing the reference to System.Xml.dll. After this, they compile System.Xml.dll the normal way. Now comes the magic. They recompile System.configuration.dll, with the part needing the reference to System.Xml.dll. Now there's a successful compilation with the circular reference.

    In short:

    • A is compiled without the code needing B and the reference to B.
    • B is compiled.
    • A is recompiled.