Simple question: why does Visual Studio "freak out" when changing Form1 name to something different
-
I do not code for a living, and infrequently use VB.net under Visual Studio. When starting a new project, the statup up form name is Form1 in vb.net (this is under VS 2022 community). If I leave the form name as Form1, then no problems when I build the project. But it seems (and this could be user error on my part), if I change the form name to something else like frmMain, then when I build the project, VS provides compiler errors such as: Error BC30420 'Sub Main' was not found in 'ModuleTest2.frmMain' or Warning BC40046 class 'frmMain' and partial class 'frmMain' conflict in namespace 'Moduletest', but are being merged because one of them is declared partial. So apparently I am doing something wrong but it seems to me that changing the first form name to something other than Form1 should not cause such a fuss. Input?
-
I do not code for a living, and infrequently use VB.net under Visual Studio. When starting a new project, the statup up form name is Form1 in vb.net (this is under VS 2022 community). If I leave the form name as Form1, then no problems when I build the project. But it seems (and this could be user error on my part), if I change the form name to something else like frmMain, then when I build the project, VS provides compiler errors such as: Error BC30420 'Sub Main' was not found in 'ModuleTest2.frmMain' or Warning BC40046 class 'frmMain' and partial class 'frmMain' conflict in namespace 'Moduletest', but are being merged because one of them is declared partial. So apparently I am doing something wrong but it seems to me that changing the first form name to something other than Form1 should not cause such a fuss. Input?
-
I do not code for a living, and infrequently use VB.net under Visual Studio. When starting a new project, the statup up form name is Form1 in vb.net (this is under VS 2022 community). If I leave the form name as Form1, then no problems when I build the project. But it seems (and this could be user error on my part), if I change the form name to something else like frmMain, then when I build the project, VS provides compiler errors such as: Error BC30420 'Sub Main' was not found in 'ModuleTest2.frmMain' or Warning BC40046 class 'frmMain' and partial class 'frmMain' conflict in namespace 'Moduletest', but are being merged because one of them is declared partial. So apparently I am doing something wrong but it seems to me that changing the first form name to something other than Form1 should not cause such a fuss. Input?
-
How are you "changing the name" - might sound like a silly question but you'd be surprised at some of the things I've seen Edit: And when - as in "immediately" or have you already written code that refers to it?
Using Visual Studio Community 2022 17.1.1 1) Select Visual Basic/desktop/windows form/.NET 6 project opens with Form1 as default no code, no changes, Build Solution, compiles with no errors 2) Select Visual Basic/desktop/windows form/.NET 6 project opens with Form1 as default using the Properties window, change the name of Form1 to frmMain, save all files no code, no other changes Build Solution = BC30451 'Form1' is not declared. It may be inaccessible due to its protection level So the question is, if I change the name of a form, do I need to do something else such that VS/VB will "update" everything to acknowledge Form1 has been renamed frmMain?
-
Using Visual Studio Community 2022 17.1.1 1) Select Visual Basic/desktop/windows form/.NET 6 project opens with Form1 as default no code, no changes, Build Solution, compiles with no errors 2) Select Visual Basic/desktop/windows form/.NET 6 project opens with Form1 as default using the Properties window, change the name of Form1 to frmMain, save all files no code, no other changes Build Solution = BC30451 'Form1' is not declared. It may be inaccessible due to its protection level So the question is, if I change the name of a form, do I need to do something else such that VS/VB will "update" everything to acknowledge Form1 has been renamed frmMain?
Nope. You do not use the Properties window to change the name of a form. Usually, you either click on the file with the form name and hit F2 to change the name of the file (which VS will happily change the name of the class for you to go along with it), or you click on the class name and hit F2 to rename the class (and all of it's other locations.)
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
Using Visual Studio Community 2022 17.1.1 1) Select Visual Basic/desktop/windows form/.NET 6 project opens with Form1 as default no code, no changes, Build Solution, compiles with no errors 2) Select Visual Basic/desktop/windows form/.NET 6 project opens with Form1 as default using the Properties window, change the name of Form1 to frmMain, save all files no code, no other changes Build Solution = BC30451 'Form1' is not declared. It may be inaccessible due to its protection level So the question is, if I change the name of a form, do I need to do something else such that VS/VB will "update" everything to acknowledge Form1 has been renamed frmMain?
-
Yes I did. Following the same steps, create a desktop VB windows form .NET 6 project, let the project come up with the standard Form1, then right click on Form1.vb in Solution Explorer, rename as frmMain.vb results in the same error message when you build it after the name change.
-
Nope. You do not use the Properties window to change the name of a form. Usually, you either click on the file with the form name and hit F2 to change the name of the file (which VS will happily change the name of the class for you to go along with it), or you click on the class name and hit F2 to rename the class (and all of it's other locations.)
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
Unfortunately, when I create a new project, let Form1 come up and then click on Form1.vb under Solution Explorer, click on Form1.vb, press F2, rename Form1 to frmMain, and then build, results in exactly the same build error.
Well, something's going on that isn't normal. You can try to get around it by double-clicking "My Project" in Solution Explorer, click the Application tab, then find the "Startup object" dropdown. Click on that and find the name of your startup form and click it, then recompile. Are there any updates to Visual Studio and Windows that haven't been installed yet?
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
Well, something's going on that isn't normal. You can try to get around it by double-clicking "My Project" in Solution Explorer, click the Application tab, then find the "Startup object" dropdown. Click on that and find the name of your startup form and click it, then recompile. Are there any updates to Visual Studio and Windows that haven't been installed yet?
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak"Well, something's going on that isn't normal." and hence the title of the post. Going to the application tab and selecting Form1 as the startup object, compiling, and then changing the form name in Solution Explorer allowed compilation without an error. However, I will note that after changing the form name from Form1 to frmMain as above, in the application tab/startup object, it is still "Form1" and not "frmMain". And while the form name in Solution Explorer is "frmMain", when you click on the form and look at Properties, it is still "Form1" My Win10 pc and VS are both up to date. Now here is where it gets even more interesting. Once again start a new project, VB/windows form/desktop/,NET 6, let the solution come up with Form1. Go to Project, Add form, and add a new form. At this time you can call it "frmMain" when it is added. Then go to Solution Explorer, select Form1 and delete it. So at this point, Form1 is gone, and only frmMain remains. Go to application tab/startup and select frmMain as the startup object. Build the solution and then you get: Error BC30456 'Form1' is not a member of 'test6'. Now VS is throwing errors on a "form" that has been deleted from the solution. So I know there are work arounds, but the (somewhat rhetorical) question is: why doesn't VS automatically update all references in the solution when a form's name is changed/deleted?
-
"Well, something's going on that isn't normal." and hence the title of the post. Going to the application tab and selecting Form1 as the startup object, compiling, and then changing the form name in Solution Explorer allowed compilation without an error. However, I will note that after changing the form name from Form1 to frmMain as above, in the application tab/startup object, it is still "Form1" and not "frmMain". And while the form name in Solution Explorer is "frmMain", when you click on the form and look at Properties, it is still "Form1" My Win10 pc and VS are both up to date. Now here is where it gets even more interesting. Once again start a new project, VB/windows form/desktop/,NET 6, let the solution come up with Form1. Go to Project, Add form, and add a new form. At this time you can call it "frmMain" when it is added. Then go to Solution Explorer, select Form1 and delete it. So at this point, Form1 is gone, and only frmMain remains. Go to application tab/startup and select frmMain as the startup object. Build the solution and then you get: Error BC30456 'Form1' is not a member of 'test6'. Now VS is throwing errors on a "form" that has been deleted from the solution. So I know there are work arounds, but the (somewhat rhetorical) question is: why doesn't VS automatically update all references in the solution when a form's name is changed/deleted?
Something is broken. I'd try uninstall VS and .NET 6 and reinstalling.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
Yes I did. Following the same steps, create a desktop VB windows form .NET 6 project, let the project come up with the standard Form1, then right click on Form1.vb in Solution Explorer, rename as frmMain.vb results in the same error message when you build it after the name change.
-
Using Visual Studio Community 2022 17.1.1 1) Select Visual Basic/desktop/windows form/.NET 6 project opens with Form1 as default no code, no changes, Build Solution, compiles with no errors 2) Select Visual Basic/desktop/windows form/.NET 6 project opens with Form1 as default using the Properties window, change the name of Form1 to frmMain, save all files no code, no other changes Build Solution = BC30451 'Form1' is not declared. It may be inaccessible due to its protection level So the question is, if I change the name of a form, do I need to do something else such that VS/VB will "update" everything to acknowledge Form1 has been renamed frmMain?
Try renaming Form1 before changing the Startup in the project properties. OR------------------------------ I have also added a form under the form name I wanted (Like Title), again doing this before changing the Startup in the project properties, Save the project exit VS, open VS and load the project. When you go back to Project the drop-down should show the form you added. Select it, return to Solution Explorer and then delete Form1 properties or at least Exclude it from the project. Both of these have worked for me.
ed