Title | List the assemblies referenced by an assembly in VB .NET |
Description | This example shows how to list the assemblies referenced by an assembly in VB .NET. |
Keywords | assembly, reference, reflection, VB .NET |
Categories | VB.NET |
|
|
This program lets you enter the location of an assembly or click a browse button to locate one. When you click the browse button, the program displays a File Open dialog. If you select an assembly and click OK, it places the location of the file you selected in its TextBox.
|
|
Private Sub btnBrowse_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnBrowse.Click
dlgFindFile.CheckFileExists = True
dlgFindFile.Title = "Select Assembly"
If dlgFindFile.ShowDialog(Me) = DialogResult.OK Then
txtPath.Text = dlgFindFile.FileName
End If
End Sub
|
|
After you enter or select a file's location and click the Go button, the prorgam creates an Assembly object that describes the location you entered. It then displays the Assembly's FullName value.
The program then loops through the collection returned by the Assembly's GetReferencedAssemblies method, displaying each referenced assembly's name.
Note that the code must include the type Assembly in square brackets because "Assembly" is also a keyword.
|
|
Private Sub btnGo_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnGo.Click
Dim assem As [Assembly] = _
[Assembly].LoadFrom(txtPath.Text)
txtResult.Text = assem.FullName()
Dim txt As String = ""
For Each referenced_assembly As AssemblyName In _
assem.GetReferencedAssemblies()
txt &= vbCrLf & referenced_assembly.FullName
Next referenced_assembly
txtReferencedAssemblies.Text = _
txt.Substring(Len(vbCrLf))
End Sub
|
|
|
|