Adding of EventHandler fails to convert properly C#->VB

2 posts, 0 answers
  1. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 14 Oct 2010 Link to this post


    I was wondering what would be the downside of converting c# event assignments:
    radButton1.Click += radButton1_Click;
    AddHandler radButton1.Click, AddressOf radButton1_click

    But from VB to C# it is working just fine.... why?

    Lately I've started to use the converter a lot, in order to provide solutions to people in both C# and vb, and because of the fact that the forum does not allow for uploading files I'm creating all the code in the examples by hand.

    It's always a pain having to convert all of the event handlers by hand....

    Best Regards,
    Emanuel Varga
  2. Todd Anglin
    Todd Anglin avatar
    2040 posts
    Member since:
    Aug 2005

    Posted 25 Oct 2010 Link to this post

    This is actually a limit of the underlying NRefactory engine that powers the Code Converter. I suggest you request this support on the SharpDevelop forums: You can further test the NRefactory engine using the simple converter provided by the core team:

    I'm not entirely sure why the core engine can convert in one direction and not other. If I had to guess, I would say the language shortcut in C# is too ambiguous. That is, "+=" can be used for a number of things in C#, such as concatenating strings or incrementing values, so it's not "guaranteed" to be an event handler. In VB, though, the explicit AddHandler can more reliably be converted.

    Hopefully a solution will be available soon to save you the manual steps! Sorry for the trouble.

Back to Top