Click here to Skip to main content
15,889,315 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionProblem in program VBA excel. Kindly guide me. Pin
Member 110635316-Sep-14 6:57
Member 110635316-Sep-14 6:57 
AnswerRe: Problem in program VBA excel. Kindly guide me. Pin
Tim Carmichael6-Sep-14 9:19
Tim Carmichael6-Sep-14 9:19 
GeneralRe: Problem in program VBA excel. Kindly guide me. Pin
Member 110635316-Sep-14 16:49
Member 110635316-Sep-14 16:49 
GeneralRe: Problem in program VBA excel. Kindly guide me. Pin
Member 110635317-Sep-14 3:46
Member 110635317-Sep-14 3:46 
GeneralRe: Problem in program VBA excel. Kindly guide me. Pin
Tim Carmichael7-Sep-14 5:59
Tim Carmichael7-Sep-14 5:59 
GeneralRe: Problem in program VBA excel. Kindly guide me. Pin
Member 110635317-Sep-14 18:27
Member 110635317-Sep-14 18:27 
GeneralRe: Problem in program VBA excel. Kindly guide me. Pin
Chris Quinn8-Sep-14 4:30
Chris Quinn8-Sep-14 4:30 
QuestionGet Attributes of External Assemblies Pin
Dominick Marciano4-Sep-14 15:09
professionalDominick Marciano4-Sep-14 15:09 
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:
VB
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:
VB
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:
VB
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:
VB
Dim currentAssembly As Assembly = Assembly.LoadFile(name)

And got a NotSupportedException and got the error message:

An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous...

But this file is not from a network location; this code and the assembly I'm trying to analyze reside on the same computer.

Finally I tried:
VB
Dim currentAssembly As Assembly = Assembly.LoadFrom(name)

And got the same exception and message as when I tried Assembly.Load.

I do understand the need to be caution loading 3rd-party libraries but I find it hard to imagine that there is no way to load an assembly simple to grab its attributes (such as the copyright notice, or custom attributes). I tried searching Google but every example I found only showed how to get attributes from the currently running assembly from within its own code. For example this works with the above code:
VB
Dim currentAssembly As Assembly = Assembly.GetExecutingAssembly


So really in the end all I'm asking is, is there someway (and if so how) to get attributes from any assembly that a user make select? Thanks in advance for any help...this has been driving me crazy for the past few hours and my current project is kind of dead right now unless I can get this to work.
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.

AnswerRe: Get Attributes of External Assemblies Pin
Richard Deeming5-Sep-14 1:46
mveRichard Deeming5-Sep-14 1:46 
GeneralRe: Get Attributes of External Assemblies Pin
Dominick Marciano12-Sep-14 6:36
professionalDominick Marciano12-Sep-14 6:36 
QuestionSynchronization of camera and shell orientation Windows 8.1 Surface Pin
Member 110572154-Sep-14 3:33
Member 110572154-Sep-14 3:33 
QuestionCopy selected listview item to a textbox VB.NET Pin
Pete_1233-Sep-14 5:49
Pete_1233-Sep-14 5:49 
AnswerRe: Copy selected listview item to a textbox VB.NET Pin
Eddy Vluggen3-Sep-14 7:14
professionalEddy Vluggen3-Sep-14 7:14 
QuestionRe: Copy selected listview item to a textbox VB.NET Pin
Pete_1234-Sep-14 7:01
Pete_1234-Sep-14 7:01 
AnswerRe: Copy selected listview item to a textbox VB.NET Pin
Eddy Vluggen4-Sep-14 8:15
professionalEddy Vluggen4-Sep-14 8:15 
AnswerRe: Copy selected listview item to a textbox VB.NET Pin
Tino Fourie24-Sep-14 6:49
Tino Fourie24-Sep-14 6:49 
Questionstring to byte, having trouble with line feed characters Pin
jkirkerx1-Sep-14 10:15
professionaljkirkerx1-Sep-14 10:15 
AnswerRe: string to byte, having trouble with line feed characters Pin
Dave Kreskowiak1-Sep-14 11:19
mveDave Kreskowiak1-Sep-14 11:19 
GeneralRe: string to byte, having trouble with line feed characters Pin
jkirkerx1-Sep-14 12:09
professionaljkirkerx1-Sep-14 12:09 
QuestionHow to use own collections in application settings in VB.NET? Pin
ponchofiesta31-Aug-14 21:35
ponchofiesta31-Aug-14 21:35 
AnswerRe: How to use own collections in application settings in VB.NET? Pin
Eddy Vluggen1-Sep-14 0:27
professionalEddy Vluggen1-Sep-14 0:27 
Questionwav to mp3 Pin
Ali Asgar29-Aug-14 4:52
Ali Asgar29-Aug-14 4:52 
AnswerRe: wav to mp3 Pin
Dave Kreskowiak29-Aug-14 5:05
mveDave Kreskowiak29-Aug-14 5:05 
GeneralRe: wav to mp3 Pin
Tim Carmichael29-Aug-14 6:28
Tim Carmichael29-Aug-14 6:28 
QuestionRe: wav to mp3 Pin
ZurdoDev29-Aug-14 5:38
professionalZurdoDev29-Aug-14 5:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.