Jan 202011

When I develop application that should be usable on Linux I usually program it in C# with Visual Studio. From time to time I test it with Mono Migration Analyzer. End result is usually runnable under Linux after some further debugging. This time I had to create application that would be used primarily under Linux so I took different approach – MonoDevelop.

Most difficult thing to get used to after transfer from Visual Studio world is lack of Windows Forms designer; everything needs to be done by hand. Doing that I stumbled upon strange behavior. Take this simple code:

private void SomeButton_Click(object Sender, EventArgs e) {
    using (var frm = new SomeForm()) {
internal class SomeForm : Form {

This code is dead simple – there is no chance of error. However this code also doesn’t work properly under Mono 2.6 (I haven’t checked other versions). Form will be shown first time button is clicked but not second time. What puzzled me the most is fact that I knew that that ShowDialog should work – other .NET application that I used under Linux worked perfectly.

First rule of bug-triage is to trim code as much as possible to determine which line is problematic one – there was nothing to trim here and I still had a bug. As it turned out, this bug shows it’s ugly head only if you don’t have any controls on Form. As soon as first control is added everything works as expected. I haven’t seen this behavior in my other applications since I never had an empty form to show.

It just shows that testing smallest possible working code is not always an answer.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>