VB WinForms Custom Sub Main not honoured

I wanted a custom Sub Main for a VB WinForms app. I’ve created the VB.Net app (.NET Framework 4.8) with VS2022. Unchecked the “Enable application framework” option of the project. Created the following module:

Module Startup
Private _mainForm As MainForm = New MainForm()
Sub Main()
_mainForm.ShowDialog()
End Sub
End Module

This worked fine when debugging with VS2022 but when I loaded the project with the AlterNET Studio Demo app, the following error was given during compilation:

Error Code: BC30738
Description: ‘Sub Main’ is declared more than once in ‘VBTest’: VBTest.My.MyApplication.Main(Args As String()), VBTest.Startup.Main()

Did I do something wrong or Scripter does not support custom Sub Main?

Thanks

Hello,
Thank you for reporting this issue. For a workaround, please add the following line in the AlternetStudio sample source code, file MainForm.Project.cs, at the end of the void OpenProject(string fileName) method:

protected void OpenProject(string fileName)
{
     //...
     scriptRun.ScriptSource.Conditionals.Add("_MYTYPE=\"WindowsFormsWithCustomSubMain\"");
}

We will consider extending our API to support this scenario better.

The workaround works for me. Thanks!

Hi,

Just a quick note that this issue has been addressed in 8.1 - it now reads MyType from the project file and passes it to the conditionals.

Regards,
Dmitry

Will upgrade to 8.1 shortly and test. Thank you.