By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,290 Members | 1,398 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,290 IT Pros & Developers. It's quick & easy.

Console app no accessible 'Main' method with an app...

P: n/a
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 MD5CryptoServiceProvider()
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(args)
hashedBytes = MD5hash(clearBytes)
Console.Write(BitConverter.ToString(hashedBytes))
End If
End Sub
End Module

May 26 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a

"TechN00b" <no**@noone.where.net> wrote in message
news:0S*******************@fe43.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 MD5CryptoServiceProvider()
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(args)
hashedBytes = MD5hash(clearBytes)
Console.Write(BitConverter.ToString(hashedBytes))
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

May 26 '06 #2

P: n/a
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********@hotmail.comREMOVETRAIL> wrote in message
news:OQ**************@TK2MSFTNGP03.phx.gbl...

"TechN00b" <no**@noone.where.net> wrote in message
news:0S*******************@fe43.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 MD5CryptoServiceProvider()
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(args)
hashedBytes = MD5hash(clearBytes)
Console.Write(BitConverter.ToString(hashedBytes))
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


May 26 '06 #3

P: n/a

"TechN00b" <no**@noone.where.net> wrote in message
news:Ze*******************@fe24.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********@hotmail.comREMOVETRAIL> wrote in message
news:OQ**************@TK2MSFTNGP03.phx.gbl...

"TechN00b" <no**@noone.where.net> wrote in message
news:0S*******************@fe43.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 MD5CryptoServiceProvider()
> 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(args)
> hashedBytes = MD5hash(clearBytes)
> Console.Write(BitConverter.ToString(hashedBytes))
> 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...2010 :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

May 26 '06 #4

P: n/a
> 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 MD5CryptoServiceProvider()
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(args)
hashedBytes = MD5hash(clearBytes)
Console.Write(BitConverter.ToString(hashedBytes))
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.GetCommandLineArgs().
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 MD5CryptoServiceProvider()
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.GetCommandLineArgs
For Each arg As String In args
clearBytes = New UnicodeEncoding().GetBytes(arg)
hashedBytes = MD5hash(clearBytes)
Console.WriteLine(arg & "= " & BitConverter.ToString(hashedBytes))
Next
Console.ReadLine()
End Sub
End Class

Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
May 26 '06 #5

P: n/a
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(cleanString);
Byte[] hashedBytes = ((HashAlgorithm)
CryptoConfig.CreateFromName("MD5")).ComputeHash(cl earBytes);
return BitConverter.ToString(hashedBytes);
}

Thanks for your help, I appreciate it.
"Mythran" <ki********@hotmail.comREMOVETRAIL> wrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...

"TechN00b" <no**@noone.where.net> wrote in message
news:Ze*******************@fe24.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********@hotmail.comREMOVETRAIL> wrote in message
news:OQ**************@TK2MSFTNGP03.phx.gbl...

"TechN00b" <no**@noone.where.net> wrote in message
news:0S*******************@fe43.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 MD5CryptoServiceProvider()
> 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(args)
> hashedBytes = MD5hash(clearBytes)
> Console.Write(BitConverter.ToString(hashedBytes))
> 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...2010 :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


May 26 '06 #6

P: n/a
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.microsoft. 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 MD5CryptoServiceProvider()
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(args)
hashedBytes = MD5hash(clearBytes)
Console.Write(BitConverter.ToString(hashedBytes))
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.GetCommandLineArgs(). 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 MD5CryptoServiceProvider()
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.GetCommandLineArgs
For Each arg As String In args
clearBytes = New UnicodeEncoding().GetBytes(arg)
hashedBytes = MD5hash(clearBytes)
Console.WriteLine(arg & "= " & BitConverter.ToString(hashedBytes)) Next
Console.ReadLine()
End Sub
End Class

Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx


May 26 '06 #7

P: n/a
> 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.GetCommandLineArgs(). 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.WriteLine(arg)
Next
Return 0
End Function

Mythran

May 26 '06 #8

P: n/a
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(input)
Dim hashedBytes As Byte() = _
(New MD5CryptoServiceProvider()).ComputeHash(clearBytes )
Console.Write(BitConverter.ToString(hashedBytes))
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

May 26 '06 #9

P: n/a
"TechN00b" <no**@noone.where.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/>

May 26 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.