Visual Studio Designer message
Asked Answered
F

3

10

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?

Flapjack answered 22/2, 2012 at 10:20 Comment(0)
O
4

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.

Opportina answered 22/2, 2012 at 10:26 Comment(4)
Thank you, Yaakov. I put a breackpoint on the InitializeComponent, but in design mode I don't stop on it... the MYUserControl itself is displaying good in the Designer. But it does not leave the form in witch is hosted to be displayed.Flapjack
I have in the UserControl a SplitContainer, but any element named SplitterPanel...Flapjack
) related: connect.microsoft.com/VisualStudio/feedback/details/540882/…Flapjack
Do a Search [In Entire Solution] for "SplitterPanel"Opportina
F
3

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.

Fanchette answered 1/11, 2012 at 13:50 Comment(0)
C
2

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.

Cortney answered 1/11, 2012 at 6:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.