List a program's loaded assemblies in C#

The key to this example is the following ListAssemblies method.

// List the assemblies.
private void ListAssemblies()
{
    lblNumAssemblies.Text = "";
    lstAssemblies.Items.Clear();
    Cursor = Cursors.WaitCursor;
    Refresh();

    foreach (Assembly assembly in
        AppDomain.CurrentDomain.GetAssemblies())
    {
        lstAssemblies.Items.Add(assembly.GetName().Name);
    }

    // Display the number of assemblies.
    lblNumAssemblies.Text =
        lstAssemblies.Items.Count.ToString() + " assemblies";
    Cursor = Cursors.Default;
}

This code loops over the Assembly objects returned by a call to AppDomain.CurrentDomain.GetAssemblies(). The program calls each Assembly's GetName method to get an AssemblyName object. It displays the value of that object's Name property in the ListBox.

   

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.