I'm trying to write a quick commandline app that takes a string from the
commandline and returns a formatted md5 hash. Unfortunately the code won't
comple and returns an error of "No accessible 'Main' method with an
appropriate signature was found"
Anyone have an idea what I need to do to fix this?
Thanks!
Full code follows:
-----------------------------------
Imports System
Imports System.Text
Imports System.Security .Cryptography
Module MD5Return
Function MD5hash(ByVal data() As Byte) As Byte()
' This is one implementation of the abstract class MD5.
Dim md5 As New MD5CryptoServic eProvider()
Dim result As Byte() = md5.ComputeHash (data)
Return result
End Function
Public Sub Main(ByVal args As Char())
Dim clearBytes, hashedBytes As Byte()
If (args Is Nothing OrElse args.Length = 0) Then
clearBytes = New UnicodeEncoding ().GetBytes(arg s)
hashedBytes = MD5hash(clearBy tes)
Console.Write(B itConverter.ToS tring(hashedByt es))
End If
End Sub
End Module 9 7835
"TechN00b" <no**@noone.whe re.net> wrote in message
news:0S******** ***********@fe4 3.usenetserver. com... I'm trying to write a quick commandline app that takes a string from the commandline and returns a formatted md5 hash. Unfortunately the code won't comple and returns an error of "No accessible 'Main' method with an appropriate signature was found"
Anyone have an idea what I need to do to fix this?
Thanks!
Full code follows: ----------------------------------- Imports System Imports System.Text Imports System.Security .Cryptography Module MD5Return
Function MD5hash(ByVal data() As Byte) As Byte() ' This is one implementation of the abstract class MD5. Dim md5 As New MD5CryptoServic eProvider() Dim result As Byte() = md5.ComputeHash (data) Return result End Function
Public Sub Main(ByVal args As Char()) Dim clearBytes, hashedBytes As Byte() If (args Is Nothing OrElse args.Length = 0) Then clearBytes = New UnicodeEncoding ().GetBytes(arg s) hashedBytes = MD5hash(clearBy tes) Console.Write(B itConverter.ToS tring(hashedByt es)) End If End Sub End Module
You Public Sub Main should read:
Public Shared Sub Main(ByVal args As String())
...
End Sub
Maybe even prepend it with the STAThread attribute too :)
Mythran
Thanks for the quick response. when I change from
Public Sub Main(ByVal args As Char())
to
Public Shared Sub Main(ByVal args As Char())
it tells me that 'Methods in a module cannot be declared 'Shared''
I'm trying this in VisualStudio 2005, if that makes any difference.
"Mythran" <ki********@hot mail.comREMOVET RAIL> wrote in message
news:OQ******** ******@TK2MSFTN GP03.phx.gbl... "TechN00b" <no**@noone.whe re.net> wrote in message news:0S******** ***********@fe4 3.usenetserver. com... I'm trying to write a quick commandline app that takes a string from the commandline and returns a formatted md5 hash. Unfortunately the code won't comple and returns an error of "No accessible 'Main' method with an appropriate signature was found"
Anyone have an idea what I need to do to fix this?
Thanks!
Full code follows: ----------------------------------- Imports System Imports System.Text Imports System.Security .Cryptography Module MD5Return
Function MD5hash(ByVal data() As Byte) As Byte() ' This is one implementation of the abstract class MD5. Dim md5 As New MD5CryptoServic eProvider() Dim result As Byte() = md5.ComputeHash (data) Return result End Function
Public Sub Main(ByVal args As Char()) Dim clearBytes, hashedBytes As Byte() If (args Is Nothing OrElse args.Length = 0) Then clearBytes = New UnicodeEncoding ().GetBytes(arg s) hashedBytes = MD5hash(clearBy tes) Console.Write(B itConverter.ToS tring(hashedByt es)) End If End Sub End Module
You Public Sub Main should read:
Public Shared Sub Main(ByVal args As String()) ... End Sub
Maybe even prepend it with the STAThread attribute too :)
Mythran
"TechN00b" <no**@noone.whe re.net> wrote in message
news:Ze******** ***********@fe2 4.usenetserver. com... Thanks for the quick response. when I change from Public Sub Main(ByVal args As Char()) to Public Shared Sub Main(ByVal args As Char()) it tells me that 'Methods in a module cannot be declared 'Shared''
I'm trying this in VisualStudio 2005, if that makes any difference.
"Mythran" <ki********@hot mail.comREMOVET RAIL> wrote in message news:OQ******** ******@TK2MSFTN GP03.phx.gbl... "TechN00b" <no**@noone.whe re.net> wrote in message news:0S******** ***********@fe4 3.usenetserver. com... > I'm trying to write a quick commandline app that takes a string from > the > commandline and returns a formatted md5 hash. Unfortunately the code > won't > comple and returns an error of "No accessible 'Main' method with an > appropriate signature was found" > > Anyone have an idea what I need to do to fix this? > > Thanks! > > Full code follows: > ----------------------------------- > Imports System > Imports System.Text > Imports System.Security .Cryptography > Module MD5Return > > Function MD5hash(ByVal data() As Byte) As Byte() > ' This is one implementation of the abstract class MD5. > Dim md5 As New MD5CryptoServic eProvider() > Dim result As Byte() = md5.ComputeHash (data) > Return result > End Function > > Public Sub Main(ByVal args As Char()) > Dim clearBytes, hashedBytes As Byte() > If (args Is Nothing OrElse args.Length = 0) Then > clearBytes = New UnicodeEncoding ().GetBytes(arg s) > hashedBytes = MD5hash(clearBy tes) > Console.Write(B itConverter.ToS tring(hashedByt es)) > End If > End Sub > End Module > > >
You Public Sub Main should read:
Public Shared Sub Main(ByVal args As String()) ... End Sub
Maybe even prepend it with the STAThread attribute too :)
Mythran
Doh! I didn't see it was a module...I don't have VS2k5, but what you can do
to possibly fix this is check the project options screen and under the Build
or Debug or General tab should be a field or set of fields that define the
main entry point or how to start the application. You may try looking for
this...(in VS2k3 it was under the General tab, field was called Startup
object).
Ya know what sucks? I'm not allowed to switch to VS2k5 until
about...umm...2 010 :P No, later this year...I hate that we aren't on top of
the tech. train, we seem to be somewhere trailing the caboose.
HTH,
Mythran
> I'm trying to write a quick commandline app that takes a string from the commandline and returns a formatted md5 hash. Unfortunately the code won't comple and returns an error of "No accessible 'Main' method with an appropriate signature was found"
Anyone have an idea what I need to do to fix this?
Thanks!
Full code follows: ----------------------------------- Imports System Imports System.Text Imports System.Security .Cryptography Module MD5Return Function MD5hash(ByVal data() As Byte) As Byte() ' This is one implementation of the abstract class MD5. Dim md5 As New MD5CryptoServic eProvider() Dim result As Byte() = md5.ComputeHash (data) Return result End Function Public Sub Main(ByVal args As Char()) Dim clearBytes, hashedBytes As Byte() If (args Is Nothing OrElse args.Length = 0) Then clearBytes = New UnicodeEncoding ().GetBytes(arg s) hashedBytes = MD5hash(clearBy tes) Console.Write(B itConverter.ToS tring(hashedByt es)) End If End Sub End Module
The Sub Main should be static and not take parameters. Additionally, it should
be inside of a class. Since we change sub Main to shared, it can no longer
directly call MD5hash as it requires an instance. Thus, we can make that
method shard as well. The command line args can be retrieved using Environment.Get CommandLineArgs ().
Below is a re-write of your sample. See if it helps.
Imports System
Imports System.Text
Imports System.Security .Cryptography
Public Class MD5Return
Private Shared Function MD5hash(ByVal data() As Byte) As Byte()
' This is one implementation of the abstract class MD5.
Dim md5 As New MD5CryptoServic eProvider()
Dim result As Byte() = md5.ComputeHash (data)
Return result
End Function
Public Shared Sub Main()
Dim clearBytes, hashedBytes As Byte()
Dim args As String() = Environment.Get CommandLineArgs
For Each arg As String In args
clearBytes = New UnicodeEncoding ().GetBytes(arg )
hashedBytes = MD5hash(clearBy tes)
Console.WriteLi ne(arg & "= " & BitConverter.To String(hashedBy tes))
Next
Console.ReadLin e()
End Sub
End Class
Jim Wooley http://devauthority.com/blogs/jwooley/default.aspx
I am unfortunately very inexperienced in VS.NET, it there a way to to this
that isn't a module? I'll put 2k3 on this machine if it helps. :-D
What's happening is that there's an application I need to interface with
that has the following as the encryprion for the password. I would like to
interface with the application using PHP, but php doesn't have an
Unicode_Encode function working yet so I figured I would just make a quick
vb console app to take a string as a command line argument and output the
hash to the console, which I can grab through php.
public static string Encrypt(string cleanString)
{
Byte[] clearBytes = new UnicodeEncoding ().GetBytes(cle anString);
Byte[] hashedBytes = ((HashAlgorithm )
CryptoConfig.Cr eateFromName("M D5")).ComputeHa sh(clearBytes);
return BitConverter.To String(hashedBy tes);
}
Thanks for your help, I appreciate it.
"Mythran" <ki********@hot mail.comREMOVET RAIL> wrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. .. "TechN00b" <no**@noone.whe re.net> wrote in message news:Ze******** ***********@fe2 4.usenetserver. com... Thanks for the quick response. when I change from Public Sub Main(ByVal args As Char()) to Public Shared Sub Main(ByVal args As Char()) it tells me that 'Methods in a module cannot be declared 'Shared''
I'm trying this in VisualStudio 2005, if that makes any difference.
"Mythran" <ki********@hot mail.comREMOVET RAIL> wrote in message news:OQ******** ******@TK2MSFTN GP03.phx.gbl... "TechN00b" <no**@noone.whe re.net> wrote in message news:0S******** ***********@fe4 3.usenetserver. com... > I'm trying to write a quick commandline app that takes a string from > the > commandline and returns a formatted md5 hash. Unfortunately the code > won't > comple and returns an error of "No accessible 'Main' method with an > appropriate signature was found" > > Anyone have an idea what I need to do to fix this? > > Thanks! > > Full code follows: > ----------------------------------- > Imports System > Imports System.Text > Imports System.Security .Cryptography > Module MD5Return > > Function MD5hash(ByVal data() As Byte) As Byte() > ' This is one implementation of the abstract class MD5. > Dim md5 As New MD5CryptoServic eProvider() > Dim result As Byte() = md5.ComputeHash (data) > Return result > End Function > > Public Sub Main(ByVal args As Char()) > Dim clearBytes, hashedBytes As Byte() > If (args Is Nothing OrElse args.Length = 0) Then > clearBytes = New UnicodeEncoding ().GetBytes(arg s) > hashedBytes = MD5hash(clearBy tes) > Console.Write(B itConverter.ToS tring(hashedByt es)) > End If > End Sub > End Module > > >
You Public Sub Main should read:
Public Shared Sub Main(ByVal args As String()) ... End Sub
Maybe even prepend it with the STAThread attribute too :)
Mythran
Doh! I didn't see it was a module...I don't have VS2k5, but what you can
do to possibly fix this is check the project options screen and under the
Build or Debug or General tab should be a field or set of fields that define the main entry point or how to start the application. You may try looking for this...(in VS2k3 it was under the General tab, field was called Startup object).
Ya know what sucks? I'm not allowed to switch to VS2k5 until about...umm...2 010 :P No, later this year...I hate that we aren't on top
of the tech. train, we seem to be somewhere trailing the caboose.
HTH, Mythran
That looks like it worked! Thanks for the explanation as well, I appreciate
the help.
Thanks Jim!
Thanks everyone!
"Jim Wooley" <ji************ *@hotmail.com> wrote in message
news:24******** *************** **@msnews.micro soft.com... I'm trying to write a quick commandline app that takes a string from the commandline and returns a formatted md5 hash. Unfortunately the code won't comple and returns an error of "No accessible 'Main' method with an appropriate signature was found"
Anyone have an idea what I need to do to fix this?
Thanks!
Full code follows: ----------------------------------- Imports System Imports System.Text Imports System.Security .Cryptography Module MD5Return Function MD5hash(ByVal data() As Byte) As Byte() ' This is one implementation of the abstract class MD5. Dim md5 As New MD5CryptoServic eProvider() Dim result As Byte() = md5.ComputeHash (data) Return result End Function Public Sub Main(ByVal args As Char()) Dim clearBytes, hashedBytes As Byte() If (args Is Nothing OrElse args.Length = 0) Then clearBytes = New UnicodeEncoding ().GetBytes(arg s) hashedBytes = MD5hash(clearBy tes) Console.Write(B itConverter.ToS tring(hashedByt es)) End If End Sub End Module The Sub Main should be static and not take parameters. Additionally, it
should be inside of a class. Since we change sub Main to shared, it can no longer directly call MD5hash as it requires an instance. Thus, we can make that method shard as well. The command line args can be retrieved using
Environment.Get CommandLineArgs (). Below is a re-write of your sample. See if it helps.
Imports System Imports System.Text Imports System.Security .Cryptography Public Class MD5Return
Private Shared Function MD5hash(ByVal data() As Byte) As Byte() ' This is one implementation of the abstract class MD5. Dim md5 As New MD5CryptoServic eProvider() Dim result As Byte() = md5.ComputeHash (data) Return result End Function
Public Shared Sub Main() Dim clearBytes, hashedBytes As Byte() Dim args As String() = Environment.Get CommandLineArgs For Each arg As String In args clearBytes = New UnicodeEncoding ().GetBytes(arg ) hashedBytes = MD5hash(clearBy tes) Console.WriteLi ne(arg & "= " &
BitConverter.To String(hashedBy tes)) Next Console.ReadLin e() End Sub End Class
Jim Wooley http://devauthority.com/blogs/jwooley/default.aspx
> The Sub Main should be static and not take parameters. Additionally, it should be inside of a class. Since we change sub Main to shared, it can no longer directly call MD5hash as it requires an instance. Thus, we can make that method shard as well. The command line args can be retrieved using Environment.Get CommandLineArgs (). Below is a re-write of your sample. See if it helps.
VB.Net 2k5 changed that much? I mean, you can't have the following work in
a class for a console application?
Public Shared Function Main(ByVal Args As String()) As Integer
For Each arg As String In Args
Console.WriteLi ne(arg)
Next
Return 0
End Function
Mythran
An alternate way of doing this, using a very similar layout the OP
originally used, is as follows:
Imports System
Imports System.Text
Imports System.Security .Cryptography
Module MD5Return
#Region " Public Methods "
''' <summary>
''' The main entry point for the application.
''' </summary>
''' <param name="Args">
''' Array of command-line arguments.
''' </param>
Public Sub Main(ByVal Args As String())
If Args.Length > 0
Dim input As String = String.Join(" ", Args)
Dim clearBytes As Byte() = _
New UnicodeEncoding ().GetBytes(inp ut)
Dim hashedBytes As Byte() = _
(New MD5CryptoServic eProvider()).Co mputeHash(clear Bytes)
Console.Write(B itConverter.ToS tring(hashedByt es))
End If
End Sub
#End Region
End Module
The reason it was failing originally was because the Main method requires
either no arguments, or a string-array ... not a character-array. Also,
make sure your Module name is the same as the file it's contained in
(otherwise, Visual Studio complains that it can't find the appropriate Main
method).
Note: removed the MD5hash method and replaced with the inline equivalent.
Replaced Char() argument with String(). Used String.Join() to join the
array into a space-delimited string.
HTH :)
Mythran
"TechN00b" <no**@noone.whe re.net> schrieb: Thanks for the quick response. when I change from Public Sub Main(ByVal args As Char()) to Public Shared Sub Main(ByVal args As Char()) it tells me that 'Methods in a module cannot be declared 'Shared''
I'm trying this in VisualStudio 2005, if that makes any difference.
Simply remove the 'Shared' keyword and change 'ByVal args As Char()' to
'ByVal Args() As String'.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dave |
last post by:
Hi,
I have done some research, trying to Clear The Screen in java code.
The first option was the obv:
system.out.print("\n\n\n\n\n\n\n\n\n\n\n\n");
then i heard about this method:
System.out.print((char)27 + "[2J");
|
by: mvdevnull |
last post by:
static void Main(string args) { DoSomething(); }
static void DoSomething() {
for (int i=0; i<=10; i++) { CallAsyncMethod(); }
}
my problem is when i run the app console exists without really completing
DoSomething()
if i add 'Console.ReadLine() to Main() then console waits until
|
by: jabailo |
last post by:
This is driving me crazy.
I finally got the Remoting sample chat application working almost.
When I run the chat client in VS.NET it goes into an endless loop --
that's because I assume that there is now way for me to interface to a
Console.ReadLine().
However, when I run it in the cmd window, it does not output any
Console.WriteLine()s ( even the "Hello" that I put as the first
|
by: Gulshan Oshan |
last post by:
I want to implement a simple console that continuously listens for an
event from a custom object. I am unable to capture the events from
the object.
If I subscribe to the events in a windows app it works fine. Any
idea?
using System;
using MyTestApp.Messaging;
using MyTestApp.BusinessLayer;
using System.Threading;
|
by: Mark Allison |
last post by:
Hi,
I have an application that I want to be to run in Console mode and GUI
mode. If no params are entered, I want the GUI fired up, if params are
entered, then go into console mode.
I believe I have all the code set up to do this, however when I issue a
Console.WriteLine instruction, nothing gets written to the console. In
fact, the command prompt comes back before the program has finished
executing. What do I need to do?
| |
by: Kevin |
last post by:
In a newsgroup thread from Jan 8, 2003 between Barry Holsinger and the
VBDotNet Team, please review this excerpt:
"You understood my problem completely. Your sample code provides a
really
elegant way to inject CrLf into the input stream, which effectively
unblocks
the ReadLine method. Last night, I had finally got the
WriteConsoleInput
|
by: Paulers |
last post by:
Hello vb.net experts :)
I am trying to program an app that resides in the system tray and I am
trying to put all my main code in sub Main(). I am getting this
errormessage at compile:
Performing main compilation...
vbc : error BC30737: No accessible 'Main' method with an appropriate
signature was found in
|
by: Joachim |
last post by:
Is there a way to set a timeout for the Console.ReadLine method?
|
by: Alexander Widera |
last post by:
hi all,
is there a possibility to call a method of a class which is in an
web-application?
perhaps it is better if i describe it this way:
IIS: "myWeb"
/App_Code/class123.cs
class123.cs : " public class class123 { .... } "
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |