Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 764
Drew Noakes Avatar asked Aug 22 '09 17:08

Drew Noakes


People also ask

What is a circular reference in Solidworks?

A circular reference happens when the dimensions or relations in a part reference another part, and that second part also references the first part. This phenomenon can happen when using “Top Down Modelling” which means parts are designed using the geometry of other parts, to ensure fit.

What is wrong with circular references?

The circular reference error message "There are one or more circular references where a formula refers to its own cell either directly or indirectly. This might cause them to calculate incorrectly. Try removing or changing these references, or moving the formulas to different cells."

What is a circular reference in programming?

A circular reference occurs when one heap variable contains a reference to a second heap variable, and the second one contains a reference back to the first. For instance, if A is an object, and somewhere in A, there is a reference to B, and within B is a reference back to A, there is a circular reference.


2 Answers

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.
like image 193
Dykam Avatar answered Sep 21 '22 20:09

Dykam


RBarryYoung and Dykam are onto something. Microsoft uses internal tool which uses ILDASM to disassemble assemblies, strip all internal/private stuff and method bodies and recompile IL again (using ILASM) into what is called 'dehydrated assembly' or metadata assembly. This is done every time public interface of assembly is changed.

During the build, metadata assemblies are used instead of real ones. That way cycle is broken.

like image 31
Srdjan Jovcic Avatar answered Sep 23 '22 20:09

Srdjan Jovcic