1

当我构建应用程序时,我有一个控件在表单设计器上崩溃,并试图弄清楚如何调试问题。

我认为要能够使用调试器,我需要做的就是启动 VS 的第二个副本并使用 Debug-Attach 来处理并附加到我的麻烦控制解决方案所在的 Visual Studio 副本。我这样做了,但是当控件崩溃时什么都没有发生,所以我知道我做错了什么...

崩溃发生在设计器中并返回消息框:

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



Exception:

Could not load file or assembly 'OtherProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.



Stack trace:

   at NameSpace.MyControl.OnPaint(PaintEventArgs e)
---------------------------
OK   
---------------------------

OtherProject 是解决方案的一部分,由项目引用,其中包含表单和自定义控件。

当我关闭消息框时,控件会在我的表单上显示控件的堆栈跟踪,但由于它不包含行号,我不知道问题出在哪里。

4

1 回答 1

4

程序集在设计时加载时的搜索路径不同,它将是 Visual Studio 的探测路径。由 Common7\IDE 中的 devenv.exe.config 文件配置。仅包含 Public Assemblies 和 Private Assemblies 文件夹。考虑项目的构建目录。

修改此 .config 文件或将程序集复制到这些文件夹之一并不完全实用。到目前为止,最好的办法是在设计时不要调用需要此程序集的代码。使用 DesignMode 属性:

    protected override void OnPaint(PaintEventArgs e) {
        if (!this.DesignMode) {
            // Runtime painting code here
            //...
        }
        base.OnPaint(e);
    }
于 2010-09-16T19:44:19.897 回答