3

I am trying to find the dependencies for a set of assemblies at runtime and I noticed that my code is implying that System.dll has a circular reference with System.Configuration.dll. I'm assuming that there isn't actually circular reference between these assemblies but can someone explain why I'm seeing the following results from this code?

var systemAssembly = Assembly.ReflectionOnlyLoadFrom("System.dll");
Console.WriteLine(systemAssembly.GetReferencedAssemblies().Select(a => a.FullName));
// Output:
// mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

var systemConfigurationAssembly = Assembly.ReflectionOnlyLoadFrom("System.Configuration.dll");
Console.WriteLine(systemConfigurationAssembly.GetReferencedAssemblies().Select(a => a.FullName));
// Output:
// mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

Note: Assembly paths have been simplified in my example.

Seth Denburg
  • 144
  • 1
  • 11
  • I can't see any message about a circular reference. Can you post all the relevant code and error messages? – rory.ap Apr 19 '17 at 20:44
  • 1
    There's nothing wrong here, circular dependencies are allowed, they're just [a pain to compile](http://stackoverflow.com/q/1316518/3764814) – Lucas Trzesniewski Apr 19 '17 at 20:49
  • @rory.ap There is no error in the code provided. The output shows that these dlls reference each other which means there is a circular dependency which confused me. – Seth Denburg Apr 20 '17 at 12:10
  • Possible duplicate of [How did Microsoft create assemblies that have circular references?](http://stackoverflow.com/questions/1316518/how-did-microsoft-create-assemblies-that-have-circular-references) – Rekshino May 12 '17 at 07:32

1 Answers1

3

Because that circular reference actually exists. Some of the .NET dlls have circular references.

Joshua
  • 40,822
  • 8
  • 72
  • 132