question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

C# -> VB: Better winforms conversion

See original GitHub issue

I tackled similar issues for VB->C# in #540, #547, #550. Here are a few known bugs that occur in converting the standard winforms generated project. They’re roughly ordered from easier to harder.

Help wanted

As well as VB’s decreasing support from Microsoft and tool vendors, VB has a reputation as a starter/prototype language, but not being so good long term, robust projects. This means the number of people trying to convert a whole winforms project C#->VB is relatively small compared to converting snippets. On top of that, there are major differences in how VB structures winforms code, so there’s a large amount of work involved in getting this right.

For those reasons this hasn’t been a priority area, only occasionally improved, but if anyone’s interested in working on this area I’d be very happy to support them doing so.

There’s a May 2019 fork of this project which was itself converted to VB, and may well have fixes for some of these issues: https://github.com/icsharpcode/CodeConverter/issues/8#issuecomment-554673493 The author is very happy for them to be reintegrated where possible

Details

  • DefineConstants in the project file needs to be converted between comma separated (VB) and semicolon separated (CSharp)
  • Everything is incorrectly qualified as [global] instead of Global
  • Add Option Infer to project file (to allow type inference)
  • Convert MultiplyAssignmentStatement
  • If one side of an & isn’t a string, call ?.ToString() on it
  • If result of a division is type int, then use integer division \
  • Add default project imports into vbproj (e.g. System)
  • Conversion is very slow for large files/projects due to the clashing renamer calling GetCsSymbolsDeclaredByMethod which calls LookupSymbols with a wide scope a lot of times
  • Convert invoke method
  • All parts of a partial class need the same modifier
  • Ensure entry point Sub Main becomes public
  • Fix resource references (I think the fix is the same as it was VB->CS)
  • CS -> VB Coalesce DefineDebug and DefineTrace into DefineConstants
  • Use https://github.com/mashmawy/FastStyleTransfer as test case
  • Generate something that works in the designer post-conversion https://github.com/icsharpcode/CodeConverter/issues/593

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jk9112605commented, Jan 27, 2021

Hah, great džob yet! There were just some mistakes like the event handles were missing. I already fixed it, it was caused by missing “WithEvents” constructorz in the Designer vb file and handles in the main vb file…

It will be great at C# to VB, if remove AddHandler in Designer.vb
convert private objName As className to Friend WithEvents objName as clasName in form.vb file At end of each event function add Handles objName.EventHandlerName

Thanks.

1reaction
GrahamTheCodercommented, Aug 6, 2020

Thanks. No need post the full list of errors unless they seem environment specific somehow - I can easily run it against the repo to get them. Let me know if there are any particular patterns you spot that haven’t been mentioned on linked issues

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I convert a windows forms app from C# to VB?
My approach would be to create a new form in VB do add some forms and add events and look at the VB...
Read more >
Convert from Visual Basic to C# in UI for WinForms
Here is my question: Is there a recommended conversion tool when moving from Visual Basic to C# that works best for Telerik Winforms?...
Read more >
Should you convert your Visual Basic .NET project to C#? ...
It depends on the rationale. If you do not need cross-platform, it is doubtful. The VB code will continue to work fine, and...
Read more >
Preparing to Convert Visual Basic to C#
Most VB to C# conversion tools translate these automatically for you, but you should get used to using the equivalent CLR objects and...
Read more >
Migrating VB.NET to C#: it's a non-trivial problem
To get 100% into .NET Core, you need to convert VB.NET to C#. If desktop apps are enough for you and your users,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found