Creating Windows Applications in VB Net


Dec 13, 2011
Programming Experience

Re-installed Visual Basic Net. Tried to create a VB Windows Forms application using the default Net 3.1. It required a Main() Sub, contrary to what the Microsoft documentation says. I have never had to do this, so I tried to create a new application using Net 5.0. The Form1 displayed. Ran the application and the form displayed as it should. Tried to change the name of the form to MainForm in the Solution Explorer and when asked said yes to change all references to Form1. Ran the application again and got the message, "The application is in Break Mode", with the message, Exception Unhandled: System.SArgumentNullException:property MainForm cannot be set to nothing.Arg_ParamName_Name.

I would appreciate advice on what I am doing wrong.
You are targeting .NET Core rather than .NET Framework. If you create a new project and, this time, select the project template that says ".NET Framework" rather than just ".NET" then you will be able to target .NET Framework 4.8 or earlier and everything will work as it did before.

.NET Core has some advantages over .NET Framework but it had to be built from the ground up, with the existing functionality of .NET Framework added bit by bit. Support for Windows Forms was added in .NET Core 3.0 but it there were significant bits missing, especially in VB projects. .NET 5.0 is basically an improved .NET Core 3.1 and a replacement for .NET Framework 4.8.

WinForms support is almost 100% in .NET 5.0 but there are still a few issues here and there. Renaming your startup form is one that I have encountered before. I think that it only happens if you use the name MainForm, because the VB Application Framework has a property with the same name. I might be remembering incorrectly though.

Regardless, if you want to stick with .NET Core then definitely use .NET 5.0 and we can sort out your renaming issue with a bit of manual editing. Otherwise, ditch this project and create a new one targeting .NET Framework and stick with that for now. .NET Framework will be around for a good while yet and there's no major advantage to using .NET Core in WinForms anyway, as it's still Windows-specific. If you need to migrate to .NET Core later, you can do so. There's no easy way to convert a project from one to the other right now but that may change in future. Even if it doesn't, you can just create a new project and then drag items from one project to the other in the Solution Explorer.
For the record, Microsoft are creating a .NET Upgrade Assistant to convert .NET Framework projects to .NET 5. It's currently in preview and I haven't used it, so I'm not sure what state it's in, but at least that means that .NET Framework projects created now should be able to be converted over relatively easily in the future.