473,379 Members | 1,260 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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

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
9 7813

"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
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

"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
> 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
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
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
> 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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
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:...
3
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...
4
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...
2
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...
6
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...
1
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...
9
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: ...
1
by: Joachim | last post by:
Is there a way to set a timeout for the Console.ReadLine method?
1
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 :...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.