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?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With