【问题标题】:Visual Studio Designer messageVisual Studio 设计器消息
【发布时间】:2012-02-22 10:20:28
【问题描述】:

当尝试在设计模式下打开一个表单 (VB.NET),其中我有一个自定义 UserControl,我看到来自 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   
---------------------------

并且表单不显示在设计器中。怎么办?

【问题讨论】:

    标签: .net vb.net visual-studio visual-studio-2010 windows-forms-designer


    【解决方案1】:

    以调试模式加载项目,并在InitializeComponent() 函数上放置一个断点以供用户控制。您可能有一些错误,即处理名为SplitterPanel 的对象,然后尝试访问它。此初始化在 Visual Studio 尝试呈现控件时运行,从而导致您看到的错误。

    【讨论】:

    • 谢谢你,雅科夫。我在 InitializeComponent 上放了一个断点,但在设计模式下我并没有停下来…… MYUserControl 本身在设计器中显示良好。但它不会离开女巫中的表单被显示。
    • 我在 UserControl 中有一个 SplitContainer,但是任何名为 SplitterPanel 的元素...
    • 在整个解决方案中搜索“SplitterPanel”
    【解决方案2】:

    删除属性

    <System.Diagnostics.DebuggerStepThrough()> _
    

    来自设计器内部的 InitializeComponent()。这将允许您逐步完成设计器。要准确找出异常是在哪里引发的,您还可以在 CLR 引发异常时中断

    Debug menu >>> Exceptions >>> 勾选“Common Language Runtime Exceptions”、“Thrown”

    通过这两个步骤,您应该能够中断引发异常的位置。

    【讨论】:

      【解决方案3】:

      您必须在表单的设计器中查看InitializeComponent 方法中的Dispose 方法的调用。类似这样的写法:

      Me.SplitterPanel.Dispose()
      

      因为这个调用对象在设计器中销毁。所以它不再存在来展示和使用它。

      删除此行将解决问题。

      【讨论】:

        猜你喜欢
        • 2023-03-03
        • 2010-12-30
        • 1970-01-01
        • 1970-01-01
        • 2013-01-15
        • 1970-01-01
        • 2016-05-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多