Share via


Circular assembly references in the .NET framework

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="https://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>

Comments

  • Anonymous
    November 23, 2013
    P.S. Please don't do this for your assemblies.

  • Anonymous
    November 25, 2013
    I believe you can (and they did) use ILMerge to do this.

  • Anonymous
    November 26, 2013
    "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...

  • Anonymous
    May 20, 2019
    Wonder if this changed in .NET Core? ?