Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Designer message

When try to open in design mode a form (VB.NET), in which I have a custom UserControl, I see the message from Visual Studio:

---------------------------
Microsoft Visual Studio
---------------------------
The control MyNamespace.MyUserControl has thrown an unhandled exception 
in the designer and has been disabled.  

Exception:
Cannot access a disposed object.
Object name: 'SplitterPanel'.

Stack trace:
---------------------------
OK   
---------------------------

And the form is not displayed in designer. What to do?

like image 371
serhio Avatar asked Feb 22 '12 10:02

serhio


3 Answers

Load up the project with Debug mode, and put a breakpoint on the InitializeComponent() function for your user control. You might have some bug in there that is disposing of an object named SplitterPanel and then trying to access it afterward. This initialization is run when Visual Studio is trying to render the control, leading to the error that you are seeing.

like image 198
Yaakov Ellis Avatar answered Oct 13 '22 19:10

Yaakov Ellis


Remove the attribute

<System.Diagnostics.DebuggerStepThrough()> _

From InitializeComponent() inside the designer. This will allow you to step through the designer. To figure out exactly where the exception is thrown, you can also break when a CLR exception is thrown by

Debug menu >>> Exceptions >>> check the box "Common Language Runtime Exceptions", "Thrown"

With these two steps, you should be able to break where the exception is thrown.

like image 22
djv Avatar answered Oct 13 '22 19:10

djv


You have to look in the designer of your form, for the call of Dispose method in InitializeComponent method. Something like this would written:

Me.SplitterPanel.Dispose()

Because of this call object destroy in the designer. So its no longer exists to display and make use of it.

Removal of this line will resolve the issue.

like image 22
NeverHopeless Avatar answered Oct 13 '22 19:10

NeverHopeless