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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TechN00b

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



  • Mythran

    #2
    Re: Console app no accessible 'Main' method with an app...


    "TechN00b" <none@noone.whe re.net> wrote in message
    news:0SFdg.6033 9$u13.45601@fe4 3.usenetserver. com...[color=blue]
    > 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
    >
    >
    >[/color]

    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

    Comment

    • TechN00b

      #3
      Re: Console app no accessible 'Main' method with an app...

      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" <kip_potter@hot mail.comREMOVET RAIL> wrote in message
      news:OQLbbGOgGH A.1856@TK2MSFTN GP03.phx.gbl...[color=blue]
      >
      > "TechN00b" <none@noone.whe re.net> wrote in message
      > news:0SFdg.6033 9$u13.45601@fe4 3.usenetserver. com...[color=green]
      > > 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
      > >
      > >
      > >[/color]
      >
      > 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
      >[/color]



      Comment

      • Mythran

        #4
        Re: Console app no accessible 'Main' method with an app...


        "TechN00b" <none@noone.whe re.net> wrote in message
        news:ZeGdg.7859 7$mJ3.28810@fe2 4.usenetserver. com...[color=blue]
        > 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" <kip_potter@hot mail.comREMOVET RAIL> wrote in message
        > news:OQLbbGOgGH A.1856@TK2MSFTN GP03.phx.gbl...[color=green]
        >>
        >> "TechN00b" <none@noone.whe re.net> wrote in message
        >> news:0SFdg.6033 9$u13.45601@fe4 3.usenetserver. com...[color=darkred]
        >> > 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
        >> >
        >> >
        >> >[/color]
        >>
        >> 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
        >>[/color]
        >
        >
        >[/color]

        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

        Comment

        • Jim Wooley

          #5
          Re: Console app no accessible 'Main' method with an app...

          > I'm trying to write a quick commandline app that takes a string from[color=blue]
          > 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[/color]

          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



          Comment

          • TechN00b

            #6
            Re: Console app no accessible 'Main' method with an app...

            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" <kip_potter@hot mail.comREMOVET RAIL> wrote in message
            news:%23ePgqTOg GHA.4976@TK2MSF TNGP02.phx.gbl. ..[color=blue]
            >
            > "TechN00b" <none@noone.whe re.net> wrote in message
            > news:ZeGdg.7859 7$mJ3.28810@fe2 4.usenetserver. com...[color=green]
            > > 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" <kip_potter@hot mail.comREMOVET RAIL> wrote in message
            > > news:OQLbbGOgGH A.1856@TK2MSFTN GP03.phx.gbl...[color=darkred]
            > >>
            > >> "TechN00b" <none@noone.whe re.net> wrote in message
            > >> news:0SFdg.6033 9$u13.45601@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
            > >>[/color]
            > >
            > >
            > >[/color]
            >
            > Doh! I didn't see it was a module...I don't have VS2k5, but what you can[/color]
            do[color=blue]
            > to possibly fix this is check the project options screen and under the[/color]
            Build[color=blue]
            > 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[/color]
            of[color=blue]
            > the tech. train, we seem to be somewhere trailing the caboose.
            >
            > HTH,
            > Mythran
            >[/color]



            Comment

            • TechN00b

              #7
              Re: Console app no accessible 'Main' method with an app...

              That looks like it worked! Thanks for the explanation as well, I appreciate
              the help.
              Thanks Jim!
              Thanks everyone!

              "Jim Wooley" <jimNOSPAMwoole y@hotmail.com> wrote in message
              news:24f81e8ee8 aa8c84eda72fb1b 17@msnews.micro soft.com...[color=blue][color=green]
              > > 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[/color]
              >
              > The Sub Main should be static and not take parameters. Additionally, it[/color]
              should[color=blue]
              > 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[/color]
              Environment.Get CommandLineArgs ().[color=blue]
              > 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 & "= " &[/color]
              BitConverter.To String(hashedBy tes))[color=blue]
              > Next
              > Console.ReadLin e()
              > End Sub
              > End Class
              >
              > Jim Wooley
              > http://devauthority.com/blogs/jwooley/default.aspx
              >
              >[/color]



              Comment

              • Mythran

                #8
                Re: Console app no accessible 'Main' method with an app...

                > The Sub Main should be static and not take parameters. Additionally, it[color=blue]
                > 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.[/color]

                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

                Comment

                • Mythran

                  #9
                  Re: Console app no accessible 'Main' method with an app...

                  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

                  Comment

                  • Herfried K. Wagner [MVP]

                    #10
                    Re: Console app no accessible 'Main' method with an app...

                    "TechN00b" <none@noone.whe re.net> schrieb:[color=blue]
                    > 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.[/color]

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

                    Comment

                    Working...