Circular references in .Net framework?

D

Dansk

Hi all,

I am currently writing some code that explores assemblies dependencies.

I start loading the first assembly with Assmebly.LoadFrom which gives me
an Assembly instance.

Then, I enumerate the AssemblyNames from the GetReferencedAssemblies()
collection.

And foreach AssemblyName in that collection, I call again Assembly.Load.

.... and so on recursively...

The first run made a call stack overflow.

After debugging a bit, I discovered that Assembly System.dll has a
dependency on System.Xml.dll, which has itself a dependency on System.dll.

The first and the second system.dll are at the same location (the GAC)

System.Xml.dll is also in the GAC.

Where am I wrong?


Thanks in advance,
Dansk.
 
M

Marc Gravell

That sounds about right...

There are a few circular references in the base libraries... not a
good idea for regular code, but arguably necessary in some scenarios.
You can't create a circular reference via the IDE - you have to use
the command line libraries and a lot of trouble.

The trick is (when walking references) to keep a track of things you
have visited, and stop when you see them again.

Marc
 
D

Dansk

Well... ok.
Thank you for the info, then, even if I find it a bit odd...

Don't worry, I won't even have the idea to try having circular
references in my projects! :)

Thanks again.
Dansk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top