4

I have one main assembly, this assembly has referenced some more assembly. I am able to get those referenced assmbly names. But, i am unable to retrive the physical path of those referenced assemblies. Any one can help me on this?

I am using the following code.

string path = Path.GetFullPath(txtFileName.Text);
Assembly a = Assembly.LoadFrom(path);

    foreach (AssemblyName an in a.GetReferencedAssemblies())  {
    Assembly asm = Assembly.Load(an);                
    MessageBox.Show(an.FullName.ToString() + "Location : " + asm.CodeBase.ToString());
    }

It gives me the path of the system assembly "mscorlib". But when it try to retrive the user created assembly, it says "The system cannot find the file specified".

Dan Puzey
  • 33,626
  • 4
  • 73
  • 96
senthil kumar
  • 151
  • 1
  • 2
  • 9
  • http://stackoverflow.com/questions/4193516/get-the-paths-of-all-referenced-assemblies - OR - http://stackoverflow.com/questions/1582510/get-pathes-of-assemblies-used-in-type – Smartis has left SO again Jun 14 '13 at 07:39

1 Answers1

4

Perhaps like this:

string path = System.Reflection.Assembly.GetAssembly(typeof(asm)).Location;

string dir = Path.GetDirectoryName( path);
Romano Zumbé
  • 7,893
  • 4
  • 33
  • 55
  • You need to put a class there that is contained in the assembly of which you want the path. – Romano Zumbé Jun 14 '13 at 07:52
  • i am getting the error at Assembly asm = Assembly.Load(an); in my code. It says not able to get the path. – senthil kumar Jun 14 '13 at 09:22
  • Lets assume, that in the assembly is a class named "FooBar" than you would adjust my code to : string path = System.Reflection.Assembly.GetAssembly(typeof(FooBar)).Location; – Romano Zumbé Jun 14 '13 at 09:33