|
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)
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:
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:
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.
|
|
|
|
|
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.
|
|
|
|
|
I am having trouble synchronizing the physical camera orientation with the shell orientation (must be a windows bug). Keep getting a picture stuck in landscape with I turn the MS Surface to portrait.
I have attempted to use the EXIF picture code and an appropriate method to determine shell orientation but the result is not consistent.
If anyone has found a good piece of vb.net code to do this function I would be grateful if you forward it to me.
|
|
|
|
|
Hi, I'm working on a small project , I'm trying to copy a selected list view item to a textbox this will then use the text in the textbox to create a text file with the name as the textbox text. here is the code I have so far:
If e.Button = Windows.Forms.MouseButtons.Left AndAlso e.Clicks = 1 Then
For Each selectedItem In selectedItems
REM
REM
txtITEM.Text = lsvRQLiveFeed.SelectedItems(0).Text
My.Computer.FileSystem.WriteAllText("C:\Users\Pete\Desktop\DJ Sync\DJ Sync\test\REQUEST\" + txtITEM.Text, +"." + ".txt", False)
Next
however I seem to get an error with the following line:
txtITEM.Text = lsvRQLiveFeed.SelectedItems(0).Text
InvalidArgument=Value of '0' is not valid for 'index'.
Parameter name: index
is there any solution I have been working for a while on this issue and I'm struggling to find a solution ?
Any help with this greatly appreciated.
Regards
Pete
|
|
|
|
|
txtITEM.Text = selectedItem.Text
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
thank you that has fixed the issue only now i need to tackle the next error:
Conversion from string "." to type 'Double' is not valid.
on this line:
My.Computer.FileSystem.WriteAllText("C:\Users\Pete\Desktop\DJ Sync\DJ Sync\test\REQUEST\" + txtITEM.Text, +"." + ".txt", False)
any ideas ?
Regards
Pete
|
|
|
|
|
Yes, it's failing on the second parameter:
, +"." + ".txt", It probably reads as 0 + "." . The second parameter is the stuff that is written to the file. If you omit the first + on that line, you'd be writing "..txt" to the file.
You might want to divide the statement over multiple lines, makes it a bit easier;
Dim sPath as String = String.Format("C:\Users\Pete\Desktop\DJ Sync\DJ Sync\test\REQUEST\{0}.txt", txtITEM.Text)
Dim sContent as String = "Whatever your content is"
My.Computer.FileSystem.WriteAllText(sPath, sContent, False) Bonus points can be earned by using the SpecialFolder enum to fetch the path to the desktop-directory, and Path.Combine to build the path.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
txtITEM.Text, +"." + ".txt", False
What's wrong there ?
You can't have a "+" next to a ","
|
|
|
|
|
I'm just trying to write a HTML text file. I can read text files, but first time writing them.
So I used the StringBuilder to build some HTML
Then I wrote a for loop to convert the stringbuilder to bytes, and then I wrote the BOM and the rest of the HTML as a file using FileStream
So I choose UT8 as the encoding, but I get the error line feed characters are inconsistent in Visual Studio when testing the file.
The original problem is when I write the file the 2nd time, and read it back, I get a BOM error, but I thought perhaps I need to fix the line feed chars first. I'm not really sure what to do here on this.
Dim m_htmlBuilder As New StringBuilder
With m_htmlBuilder
.Append("<div style=""width: " & p_width & "; Height: " & p_height & "; text-align: center; margin: 0px auto; background-color: rgb(28,134,238);"">" & vbCrLf)
.Append(" <span style=""color: rgb(255,255,255); font-size: 1.0em; font-weight: bold; line-height: " & p_height & ";"">" & vbCrLf)
.Append(p_html_name & " is now ready for use" & vbCrLf)
.Append(" </span>" & vbCrLf)
.Append("</div>" & vbCrLf)
End With
Dim m_htmlStream As String = m_htmlBuilder.ToString
Try
Dim htmlLen As Long = m_htmlStream.Length
Dim charArray As Char() = New Char(htmlLen) {}
Dim byteArray() As Byte = New Byte() {}
For cdx As Integer = 0 To htmlLen - 1
charArray(cdx) = m_htmlStream(cdx)
Dim charVal As Char = charArray(cdx)
Array.Resize(byteArray, byteArray.Length + 1)
byteArray(byteArray.Length - 1) = UTF8CharToByte(charVal)
Next
Using htmlStream = New FileStream(p_html_path, FileMode.Create, FileAccess.Write)
Using writer As BinaryWriter = New BinaryWriter(htmlStream, Encoding.UTF8)
Dim [utf8] As Encoding = Encoding.UTF8
Dim preamble As Byte() = [utf8].GetPreamble()
writer.Write(preamble)
writer.Write(byteArray, 0, byteArray.Length - 1)
If Not (writer Is Nothing) Then
writer.Close()
writer.Dispose()
End If
End Using
If Not (htmlStream Is Nothing) Then
htmlStream.Close()
htmlStream.Dispose()
End If
End Using
|
|
|
|
|
Yeah, that's doing it ........how can I put this........ the hard way.
How about using an overload of the StreamWriter class to handle all the crap for you? Oh, and you don't even have to call ToString on the StringBuilder.
Sub Main()
Dim sb As New StringBuilder()
sb.AppendFormat("Some formatted text containing {0} lines..." & Environment.NewLine, 3)
sb.AppendLine("You don't need vbCrLf at the end of every line if you use the ")
sb.AppendLine("AppendLine method of the StringBuilder instead of Append.")
Using fs As New FileStream("C:\Text.txt", FileMode.Create)
Using sw As New StreamWriter(fs, Encoding.UTF8)
sw.Write(sb)
End Using
End Using
End Sub
|
|
|
|
|
I really wanted to make that work, I'll just save it for another day. Just wanted to work with bytes for the experience.
I ended up just using 3 lines of code using textwriter before your post, but switched to your example for 5 lines and UTF8
On the read side I did the same thing in reverse. But I just changed that to the opposite of your example.
Now everything works from start to finish. Just modified everything and tested it 10 different ways.
Well thanks for the KISS, I made something really simple complex.
|
|
|
|
|
I'm writing a program in VB.NET and try to save different profiles via the application settings (project settings -> settings tab).
I created a Profile class and a collection class of that. If I choose this collection as settings type, I can add multiple objects with type System.Object, but I need to add my Profile object.
How can I add a collection of my Profile objects with the settings editor? Whats wrong with my code?
Profile.vb
Imports System.Configuration
<SettingsSerializeAs(Configuration.SettingsSerializeAs.Xml)> _
Public Class Profile
Public Property Name As String
Public Property ViewerCommand As String
Public Property ViewerPath As String
Public Property StartService As Boolean
Public Property StopService As Boolean
End Class
<SettingsSerializeAs(Configuration.SettingsSerializeAs.Xml)> _
Public Class ProfileCollection
Inherits CollectionBase
Public Shadows Function Add(ByVal ProfileObject As Profile) As Profile
MyBase.List.Add(ProfileObject)
Return ProfileObject
End Function
Public Shadows Sub Remove(ByVal ProfileObject As Profile)
MyBase.List.Remove(ProfileObject)
End Sub
End Class
A screenshot of the current behavior
The type is VNC_Manager.ProfileCollection for the setting called "Profiles".
http://i.stack.imgur.com/4Oaf8.png[^]
On the right side there should be Name, ViewerCommand, ...
If I use VNC_Manager.Profile for type, I also can't see Name, ViewerCommand... So there seems to be a problem with the Profile class(?)
|
|
|
|
|
|
vb.net code for convert a wav file to mp3 file
|
|
|
|
|
If you're looking for someone to write this code for you, you've come to the wrong place.
If you're looking for example code, type the text from your post into Google and start reading. This is what is called "research".
|
|
|
|
|
Yeah, Google it with your favourite search engine (see the lounge postings for ideas).
|
|
|
|
|
Where are you stuck?
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
multidimensional hierarchy is needed for my report ............. please help me .
my query is like below
SHAPE {SELECT * FROM job_table WHERE job_id = ?} AS parentCMD APPEND ({SELECT *
FROM ((job_table AS p INNER JOIN
job_team AS jt ON p.job_id = jt.job_id) INNER JOIN
Team_Member AS tm ON jt.Member_ID = tm.Member_ID)} AS childCMD RELATE 'job_id' TO 'p.job_id') AS childCMD,({SELECT *
FROM (job_table AS jobTBL INNER JOIN
job_tjb AS jt ON jobTBL.job_id = jt.job_id)} AS tjbCMD RELATE 'job_id' TO 'jobTBL.job_id') AS tjbCMD
|
|
|
|
|
Upgrade to a programming language that is less than 10 years out of date?
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
|
If you provide a code sample of what you've done, you are much more likely to receive assistance.
Simply asking someone to do the work for you if unlikely to produce any positive results.
|
|
|
|
|
There are a million and 1 ways to do this. Where are you stuck?
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Down vote countered - I was going to be a little more cutting in my remarks to the OP.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|