简体   繁体   中英

How to get the physical path of the referenced assemblies

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".

Perhaps like this:

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

string dir = Path.GetDirectoryName( path);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM