Monday, December 24, 2007

No accessible 'Main' method with an appropriate signature was found

I was working in a project that was a windows application, but I decided to change it to a console application instead. I changed the type to console and selected Sub Main as my startup object. When I compiled it I got the fallowing error: Error 54 No accessible 'Main' method with an appropriate signature was found.

I expected problems because I knew I did not have the Sub Main defined in my project. I added a class file and entered the fallowing code:

Public Class Main

Public Shared Sub Main()

Application.Run(New Form1)

End Sub

End Class




Several examples I saw had main defined with (ByVal args() As String) as the parameter. One thread on the subject indicated that you can add a module instead of a class. Here is the syntax for that.

Module Main

Public Sub Main(ByVal args() As String)

Application.Run(New Form1)

End Sub

End Module




You will notice that the shared keyword is left off inside the module.

No comments: