icsharpcode / CodeConverter

Convert code from C# to VB.NET and vice versa using Roslyn
https://icsharpcode.github.io/CodeConverter/
MIT License
840 stars 218 forks source link

Large number of problems trying to convert large VB project in large solution to c# #1045

Closed ibelchamber closed 4 months ago

ibelchamber commented 12 months ago

We have a solution with 33 projects, It is currently in UWP + Xaml Islands, as this seems to be not the way forwards now I would like to try to migrate to WinUi3 which does not support VB, so my first step is to convert vb to c#.

First attempt on the first VB project looked quite good, only about 33 errors. Most of these were things going wrong converting subs / functions that had Optional byref parameters. I removed byref in the original VB (was not needed) then A load more came up. Fixed those and retried, then I was up to 364 errors, mostly it seems:

enums have been converted to ints colours are not correctly converted: CS1503 Argument 2: cannot convert from 'Windows.UI.Color' to 'Global.Windows.UI.Color?' there are probably 20 different error types.

It would take days to try to sort this out, but my concern would be that after that, the number of problems will just increase again.

What is the best approach to try to progress this? Would anyone be interested in taking a copy of our solution and investigating the faults? It does seem to be exposing a vast number of issues that maybe obstruct smaller conversions but maybe not as badly,

Thanks.

GrahamTheCoder commented 12 months ago

Thanks for getting in touch. I'd agree that a conversion of that size is likely to take more than a few days to get compiling in c#.

The approach I'd suggest is to initially go one project at a time from the bottom of the dependency tree to keep the errors manageable. First just spike it, E. G. Regex or comment out problematic bits until it compiles just to see the scale of issues. There are some other hints on general approach on the wiki. But basically, commit often.

For each type of issue, we will need to get a minimal repro for a unit test so we can fix it.

If you can share the git repo or zipped version of the solution causing issues it will definitely be useful. Though to be clear, I'm not intending to deliver a converted repo back, or even promising to make the converter all work perfectly for it. I also can't guarantee when I'll have time to work on improving conversion for the types of errors found - December is very busy for me.

ibelchamber commented 12 months ago

Many thanks for your response. we will investigate further and may have more feedback / questions. We are also trying to evaluate how confident we are with winui3, the concern is that we could put man years of effort into porting to that and then have to do it all again. It is a nightmare trying to develop very large applications with long lifetime with Microsoft keeping on changing things.

GrahamTheCoder commented 12 months ago

Sorry, yes since your focus is UI you should probably start at the top of the tree with ui projects. Be aware that integration points with the many ui frameworks is a weak point of the converter. But usually the issues are simple but widespread.

Converting to c# is likely to set you up well for the future in any case, but obviously does have risk and time cost.

Please do open an issue for any individual errors you find, or send the whole solution (just email directly if you don't want to share it publicly)

GrahamTheCoder commented 11 months ago

Reopen if you can share any details of particular issues

ibelchamber commented 11 months ago

Hi apologies too much going on, I would really appreciate you having a look at the solution but do not want to provide it publicly, I have a googledrive link of the zip, can I send it to you privately?

GrahamTheCoder commented 11 months ago

Yes, that's fine so long as you're happy with me using it for the purposes of manual testing and won't hold me liable for any damages caused if it is leaked somehow if future. I'll take reasonable steps to protect it as I would my own data. If you're happy with that, let me know and send a link to grahamthecoder@gmail.com.

Additionally, let me know whether you would you be ok with me deriving automated tests from small subsections of code. I can change variable/method names if you like for example, but if you have some absolutely crucial secret algorithm(s), you should say no (or omit those key parts).

ibelchamber commented 11 months ago

Hi Graham,

Many thanks this is most helpful, I will email you directly,

Ian