views:

241

answers:

5

I have created a custom control that is included in a control library that is referenced by a VB Forms application.

When I modify the control, and have the application open in a VS window, VS usually asks me if I want to reload items that have changed.

However, a couple of times, it has not asked me this, and when I go to open the form that contains the modified control, I get an error window warning me that if I ignore the error message and continue, then I risk making VS unstable. I've learned to ignore this error message, continue, and immediately save the form to a new file.

Has anyone else had this problem? Is this a bug in VS?

A: 

Its more likely a bug in your control. The VS form designer will actually create an instance of your control in the designer, so if your control is doing anything like reaching out to a database, its going to throw an exception and prevent the form from rendering correctly.

Its actually wholly possible to attach a debugger from another instance of Visual Studio and put breakpoints on lines of code in your user control -- from there, you can narrow down which lines of code are causing a problem.

Once you find the line which is causing the problem, wrap it with this:

If Me.DesignMode Then
    Return
End If

The DesignMode property returns True when the control is being rendered in the designer, false otherwise. This property is not 100% reliable. If you have a control within another control, the child control's DesignMode property will be False. Painful painful painful to work with when you have several layers of nested controls.

Juliet
+2  A: 

You are probably serializing properties you don't intend to, and causing unexpected changes. Look at the designer code and see what the designer is creating for your control.

You can add the following attribute to properties to prevent serialization:

Imports System.ComponentModel

    <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
eschneider
A: 

The problem is not with the control itself - after I quit VS, and load the project back in (with the new emergency save copy of the form that was trashed) it works fine.

So, I don't think there is any problem with the code written, since everything works fine as long as I don't have the application open while modifying the control (which is in another library).

Could the reason be related to unsaved changes in the form, and the change created by modifying the form?

Larry Watanabe
Look at the designer generated code (for the trashed form) as I stated above, there is some serialize which should not be.
eschneider
Thanks, this seems to have been the cause of the problem.
Larry Watanabe
No problem, sorry I could not explain it better, but it is a tricky one.
eschneider
A: 

I've had this problem too. The best way to avoid it is to create a new version of your control, e.g. SimpleKeyboard3, then make sure to remove the old one from your form, and then replace it with the new one. Otherwise the form might be making reference to properties or other things that can no longer be referenced.

Or, you can delete the control from your form, then modify the control, then add it back to your toolbar and then drag it back into your form.

Even if it's trashed, you can still fix it by choosing the "ignore and continue .. this may make the designer unstable" option so that you can delete the control.

Larry Watanabe
A: 

The problem seemed to be references to controls that no longer exist, sometimes because the .dll htat the control is in is no longer available. I discovered this when doing a "Clean All" on my control library, and then getting the error when I opened a form referencing the control - the problem when away when I "Rebuilt all" in the control library.

Larry Watanabe