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.

VB -> C#: Missing event wiring for overridden members

See original GitHub issue

VB.Net input code

Private Sub btn2_Click(sender As Object, e As EventArgs) Handles btn2.Click
        lblMsg.Text = "Copying data From clipboard..."
        lblMsg.Refresh()
        Utils.ClipboardToDGV(uGrid.dgvData, True)
        lblMsg.Text = CStr(uGrid.dgvData.Rows.Count) & " rows are ready to upload."
        lblMsg.Refresh()

        btn5.Visible = True
    End Sub

Erroneous output

No event wiring. Function is converted correctly but event handler function is not wired to btn2.Click event

Expected output

Event handler function should be wired to btn2.Click event

Details

  • Product in use: VS extension
  • Version in use: 2.11.106.19330
  • Did you see it working in a previous version, which?
  • Any other relevant information to the issue, or your interest in contributing a fix.

Problem occurs on forms that inherit base form which has the definition of btn2 In the base form, vb.net code had a public Button btn2, but in the c# version it has a private Button _btn2 and a getter/setter called btn2

The designer code for child forms are referencing in some cases the private class member, e.g. _btn2, which causes an error since _btn2 is private, and in other cases the public member, e.g. btn3. The modifier issue is minor, the main problem is the wiring of events.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
plalonde4321commented, Oct 7, 2021

Yes that’s the jist of it. The button defined in the base class no longer has its click event wired to the handler defined in the inheriting class. The “expected CSharp output” from your comment has the correct event wiring.

0reactions
GrahamTheCodercommented, Dec 21, 2021

I’ve made some decent progress on the small test case now. I’ll try it on some real apps tomorrow hopefully and refine it. If you’re willing to try out a prerelease build from the build system (or build it locally and try it), let me know and I can give some hints on doing so if it’s not obvious (in particular something a bit odd has happened with the local debug options attaching a debugger when building from source, so it’s best to just build it then install the output and restart)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Thread: How do you implement an abstract event in VB?
I tried overriding add_DirectIOEvent - it says it's not overridable. I tried creating an add_DirectIOEvent method. It gives me this: ' ...
Read more >
Handling and Raising Events
Typically, to raise an event, you add a method that is marked as protected and virtual (in C#) or Protected and Overridable (in...
Read more >
How to override an event handler in the derived class ...
To override a virtual member from the base class, the derived class needs to use the override modifier, not the virtual modifier.
Read more >
Troubleshooting Inherited Event Handlers - Visual Basic
Code in Event Handler Executes Twice for Every Call. An inherited event handler must not include a Handles clause. The method in the...
Read more >
Overriding Events in VB
Is there a way to translate this code in VB? Most of it is easy, but I can't figure out a way to...
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