ChiaHsien
ChiaHsien

Reputation: 325

Get dll file extension by System.Reflection.Assembly

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);
}

Upvotes: 0

Views: 1477

Answers (2)

Mark PM
Mark PM

Reputation: 2919

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));
        }

Upvotes: 3

Jens Meinecke
Jens Meinecke

Reputation: 2940

foreach (System.Reflection.AssemblyName data in names)
{
   listBox2.Items.Add(data.FullName);
}

Upvotes: -1

Related Questions