Get Attributes of External Assemblies
-
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 anAssembly
object. This class is not a concern; I have already tested all the code within this class by using theGetExecutingAssembly
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 PropertyPublic Sub New(assembly As Assembly)
_assembly = assembly
End SubEnd 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.CopyrightEnd Sub
How can I using
assemblyName
to create thecurrentAssembly
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
-
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 anAssembly
object. This class is not a concern; I have already tested all the code within this class by using theGetExecutingAssembly
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 PropertyPublic Sub New(assembly As Assembly)
_assembly = assembly
End SubEnd 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.CopyrightEnd Sub
How can I using
assemblyName
to create thecurrentAssembly
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
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
-
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
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.