Circular assembly references in the .NET framework

Circular assembly references in the .NET framework

Rate This
  • Comments 3

It was a surprise to me when I discovered that a lot of assemblies in the .NET BCL reference each other in a circular manner:

image

Cycles in the reference graph are in red. Apparently there is special MSBuild magic used when compiling these assemblies. My guess would be that proper factoring of the assemblies into a DAG without cycles would create too many assemblies and the .NET team opted against that.

I’ve generated this .dgml file to play with the assembly reference graph. You can open it in Visual Studio, and use the Layout –> Analyzers –> Circular References Analyzer on the graph to highlight the cycles in red like I did in the image above. Find Hubs and Unreferenced Nodes are also interesting.

Here’s a fragment of the file with just the 4 assemblies:

<DirectedGraph xmlns="http://schemas.microsoft.com/vs/2009/dgml">
  <Nodes>
    <Node Id="mscorlib" />
    <Node Id="System" />
    <Node Id="System.Core" />
    <Node Id="System.Xml" />
  </Nodes>
  <Links>
    <Link Source="System" Target="mscorlib" />
    <Link Source="System" Target="System.Xml" />
    <Link Source="System.Core" Target="mscorlib" />
    <Link Source="System.Core" Target="System" />
    <Link Source="System.Core" Target="System.Xml" />
    <Link Source="System.Xml" Target="mscorlib" />
    <Link Source="System.Xml" Target="System.Core" />
    <Link Source="System.Xml" Target="System" />
  </Links>
</DirectedGraph>
  • P.S. Please don't do this for your assemblies.

  • I believe you can (and they did) use ILMerge to do this.

  • "would create too many assemblies"  - how true is this :) We have 327 now, but no cycles at all :)

    I wish some day dependency management will be decoupled from 'assemblies' in some way...

Page 1 of 1 (3 items)
Leave a Comment
  • Please add 5 and 4 and type the answer here:
  • Post