serhio
serhio

Reputation: 28586

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?

Upvotes: 10

Views: 5564

Answers (3)

djv
djv

Reputation: 15774

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.

Upvotes: 3

NeverHopeless
NeverHopeless

Reputation: 11233

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.

Upvotes: 2

Yaakov Ellis
Yaakov Ellis

Reputation: 41480

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.

Upvotes: 4

Related Questions