Results 1 to 9 of 9

Thread: Error message: BC30420

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2017
    Posts
    71

    Error message: BC30420

    Hi All, I have an error message on frequent basis:

    BC30420 'Sub Main' was not found in ConsoleApp1.Module1

    even my code is very simple such as

    Code:
    Module Module1
        Sub Main()
    
            MsgBox("TEST")
    
        End Sub
    
    End Module
    I have read online, tried to delete the whole code, restarted the new project a few times but the same error keeps popping up. I could not fix myself. PLEASE PLEASE help me out.

    Thank you All

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Error message: BC30420

    If this happens with multiple projects then it might be that VS is corrupted in some way so you should probably do a repair.

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Error message: BC30420

    The first thing I would try would be to create a simple windows forms application rather than a console app. I wouldn't add anything to it, just take the defaults. By doing this, you get a super minimal program with everything that MS thinks you should have. If it runs, then it suggests that the installation may not be the problem. It doesn't PROVE that the installation is ok, but it does suggest that it is. Of course, if it doesn't run, then you can be fairly certain that your installation is corrupt.
    My usual boring signature: Nothing

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Apr 2017
    Posts
    71

    Re: Error message: BC30420

    Ok....I will try suggestions from both of you, jmc and Shaggy, and see what happens today.

    Thanks

  5. #5
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Error message: BC30420

    The Console Application template is even simpler and more barebones than a WinForms app template. My guess is the install's corrupted in some way.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Apr 2017
    Posts
    71

    Re: Error message: BC30420

    HI Shaggy and Sitten,

    I removed VS professional and reinstall with VS 2017 Community.

    I create a super-mini window form without any buttons or text, or sub, debugged it and it works fine. However, when create a new project, debug it, it has same error issue above.

    Below is my simple Console code

    Code:
    Module printCAPTURES
    
        Sub Main()
    
            MsgBox("TEST")
    
        End Sub
    
    End Module
    What would the problem be?

    Any help is much appreciated.
    Last edited by NeedHelpVB; Apr 21st, 2017 at 10:36 PM.

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Error message: BC30420

    The problem is that you renamed the module.

    To fix the problem, go into Project | Properties. On the Application tab you have a drop down for the startup object. Choose one of the items from the drop down, and it will work. You probably only have two items on that dropdown, one being printCaptures, and the other being Sub Main. I doubt it matters which one you choose.

    In some fashion, this was probably the original problem, as well. The IDE chooses a startup object automatically, and normally it chooses it correctly, such that you don't usually have to even look at that startup object field in the Project | Properties. I haven't paid any attention to that in well over a decade. I had to play around with it just to see if I could reproduce the error, since I was so unfamiliar with it. However, all that was necessary to reproduce the error was to change the name of the module without changing the startup object.
    My usual boring signature: Nothing

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Apr 2017
    Posts
    71

    Re: Error message: BC30420

    Thanks Shaggy. I will do and try not to change name of the modules if I do not have to.

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Error message: BC30420

    That's not the right message to take from that. You SHOULD change the default names on everything. A name should reflect the purpose of the item, and the default names never do. What has me a bit puzzled about this is that the IDE generally handles this piece for you, or at least does a better job of it than it did in this case. If I create a Forms application, the default form is called Form1. I never leave it at that name except for disposable test applications, but I also don't remember changing the startup object very often since VS 2003. Therefore, I thought that if the startup object was Form1, and you rename Form1 to MyMainForm, then the IDE would automatically change the startup object to MyMainForm, as well. That's not what is happening with a console app. The default object is Module1, and the startup object is Module1 by default. If you then change the name of Module1 to printCAPTURES, I would expect that the startup object would also change to printCAPTURES, but it does not. In fact, it remains Module1, which no longer exists, so you get the error you are seeing.

    The other alternative for Startup object is Sub Main if you just create a new console application. If the default startup object was Sub Main rather than Module1, then changing the name of the module would have no effect at all. Why the default startup object is Module1, then, is a bit of a mystery, though not one interesting enough to spend any time on.

    However, the likely reason that we went the wrong way on this, at first, is a combination of the first snippet showing Module1, and the fact that people rarely make console applications. I believe the IDE does it the way you expect it for a forms application, but apparently not for a console application. Therefore, if you make a console application, you have to set the startup object yourself, or you get the error you got.

    The only thing this doesn't do is answer the original question.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width