0

I am going to implement a function that can extract all referenced dll files in an exe.

I'm using "System.Reflection.Assembly" to do it.

But I have no idea how to get file extension.

For example, text.exe contains x.dll, y.dll and z.dll

Above code returns only x, y, z.

Anyone know how to to it?

Thank you all.

System.Reflection.Assembly assemblyFile = System.Reflection.Assembly.LoadFile(exePath);

System.Reflection.AssemblyName[] names = assemblyFile.GetReferencedAssemblies();

foreach (System.Reflection.AssemblyName data in names)
{
     listBox2.Items.Add(data.Name);
}
ChiaHsien
  • 315
  • 1
  • 3
  • 10

2 Answers2

3

If you are looking for the full file name (eg x.dll) then use this:

        foreach (System.Reflection.AssemblyName data in names)
        {
            var assembly = System.Reflection.Assembly.ReflectionOnlyLoad(data.FullName);
            listBox2.Items.Add(System.IO.Path.GetFileName(assembly.Location));
        }
Mark PM
  • 2,909
  • 14
  • 19
-1
foreach (System.Reflection.AssemblyName data in names)
{
   listBox2.Items.Add(data.FullName);
}
Jens Meinecke
  • 2,904
  • 17
  • 20
  • 2
    While this code snippet may solve the question, [including an explanation](//meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. Please also try not to crowd your code with explanatory comments, this reduces the readability of both the code and the explanations! – kayess Apr 10 '17 at 09:19