views:

36

answers:

3

Hi all,

there is a lot of examples how to load all dependencies from some assembly like:

var assembly = Assembly.ReflectionOnlyLoadFrom(assemblyPath);
foreach (var assemblyName in assembly.GetReferencedAssemblies()) {
  try {
    Assembly.ReflectionOnlyLoad(assemblyName.FullName);
  } catch {
    Assembly.ReflectionOnlyLoadFrom(Path.Combine(Path.GetDirectoryName(assemblyPath), assemblyName.Name + ".dll"));
  }
}

but what if one of dependencies is not ".dll" but ".exe" ? Do I need for that ".exe" assembly again to call recursivly GetReferencedAssemblies() in foreach loop ? Is there a danger of getting circular dependancy ?

br, Milan

+2  A: 

An assembly that is a dll can just as well as an exe have references to other assemblies; there is no difference between them from that perspective.

Fredrik Mörk
Please see my comment on Simpzon answer.
milan
+4  A: 

You should be able to use the exe just like any other dll. It just has this extra bonus that it can be executed standalone.

Simpzon
First question is how to recognize that some assemblyName is exe ? I get just its name e.g. "MyFile" but no extension. In my case I know that "MyFile" is exe but in general case I do not know its extension, so the last line in code example I gave will give exception. How to deal witht that, any idea ? another exception handler would be too much...
milan
Assembly.CodeBase should tell you the file name.System.IO.File... should enable you to get the extension, but I think you don't need the file-extension anymore, once you have the filename.
Simpzon
A: 

GetReferencedAssemblies() does not return the entire dependency tree (dll or exe doesn't make a difference), so you will need a solution that traverses the tree. See this article http://msdn.microsoft.com/en-us/magazine/cc163641.aspx.

insipid
If GetReferencedAssemblies does not return all assemblies is there any option using reflection methods to retrieve all dependencies ?
milan
The article explains how to get all the dependencies using the GetReferencedAssemblies() method. As for a single method that returns the whole tree, I do not know of one myself.
insipid