Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Get Attributes of External Assemblies

Get Attributes of External Assemblies

Scheduled Pinned Locked Moved Visual Basic
questionhelptutorialannouncement
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dominick Marciano
    wrote on last edited by
    #1

    I'm trying to write a method that can take the path to any valid assembly and then analyze its attributes, such as title, company, and trademark, but especially custom attributes. Although I will want to get standard assembly attributes, my main purpose for this application is to get information from a custom attribute I created in another project that I add to most of my assemblies. I have already have a method that take an assembly as a parameter and can pull the information I need. I also have a method that displays an open file dialog window where a user can select a file and then the method determines if it is a valid assembly. What I can't figure out is how to take the path to the assembly file, create an assembly object from it, and then pass it to the method that get the attributes. He is a VERY stripped down version of the AssemblyAttributes class just to demonstrator the constructor that take an Assembly object. This class is not a concern; I have already tested all the code within this class by using the GetExecutingAssembly method and all the code worked fine:

    Public Class AssemblyAttributes

    Private _assembly as Assembly

    Public Readonly Property Copyright as string
    Get
    Return GetCopyrightString
    End Get
    End Property

    Public Sub New(assembly As Assembly)
    _assembly = assembly
    End Sub

    End Class

    And then I have my method, that gets called from a button's click event, which takes the path to an assembly (the stream writer is used later in code that is not shown to output the attribute information). This is the method where I have having trouble:

    Private Sub GetAssemblyAttributes(assemblyName As String, ByRef sw As StreamWriter)

    Dim currentAssembly As Assembly

    Dim assemblyAttributes As New AssemblyAttributes(currentAssembly)
    Dim copyright As String = assemblyAttributes.Copyright

    End Sub

    How can I using assemblyName to create the currentAssembly object? I have tried:

    Dim currentAssembly As Assembly = Assembly.Load(name)

    And got a FileLoadException and got the error message: Could not load file or assembly 'C:\\[PathToAssembly]\\[AssemblyTryingToAnalyze].dll' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047) Next I tried:

    Dim currentAssembly As Assembly = Assembly.LoadFile(name)

    An

    Richard DeemingR 1 Reply Last reply
    0
    • D Dominick Marciano

      I'm trying to write a method that can take the path to any valid assembly and then analyze its attributes, such as title, company, and trademark, but especially custom attributes. Although I will want to get standard assembly attributes, my main purpose for this application is to get information from a custom attribute I created in another project that I add to most of my assemblies. I have already have a method that take an assembly as a parameter and can pull the information I need. I also have a method that displays an open file dialog window where a user can select a file and then the method determines if it is a valid assembly. What I can't figure out is how to take the path to the assembly file, create an assembly object from it, and then pass it to the method that get the attributes. He is a VERY stripped down version of the AssemblyAttributes class just to demonstrator the constructor that take an Assembly object. This class is not a concern; I have already tested all the code within this class by using the GetExecutingAssembly method and all the code worked fine:

      Public Class AssemblyAttributes

      Private _assembly as Assembly

      Public Readonly Property Copyright as string
      Get
      Return GetCopyrightString
      End Get
      End Property

      Public Sub New(assembly As Assembly)
      _assembly = assembly
      End Sub

      End Class

      And then I have my method, that gets called from a button's click event, which takes the path to an assembly (the stream writer is used later in code that is not shown to output the attribute information). This is the method where I have having trouble:

      Private Sub GetAssemblyAttributes(assemblyName As String, ByRef sw As StreamWriter)

      Dim currentAssembly As Assembly

      Dim assemblyAttributes As New AssemblyAttributes(currentAssembly)
      Dim copyright As String = assemblyAttributes.Copyright

      End Sub

      How can I using assemblyName to create the currentAssembly object? I have tried:

      Dim currentAssembly As Assembly = Assembly.Load(name)

      And got a FileLoadException and got the error message: Could not load file or assembly 'C:\\[PathToAssembly]\\[AssemblyTryingToAnalyze].dll' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047) Next I tried:

      Dim currentAssembly As Assembly = Assembly.LoadFile(name)

      An

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Have you tried Assembly.ReflectionOnlyLoadFrom[^]?


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      D 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        Have you tried Assembly.ReflectionOnlyLoadFrom[^]?


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        D Offline
        D Offline
        Dominick Marciano
        wrote on last edited by
        #3

        Wow...how did I miss that one?! I guess that is what I get for working on it till 3AM. I will take a look at that tonight when I get home. Thanks!

        A black hole is where God tried to divide by zero. There are 10 kinds of people in the world; those who understand binary and those who don't.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups