Visual Studio 设计器中的调试控件崩溃

发布于 2024-09-19 06:11:45 字数 848 浏览 4 评论 0原文

当我构建应用程序时,我有一个控件在表单设计器上崩溃,并且正在尝试找出如何调试该问题。

我认为我需要做的就是能够使用调试器启动 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 是解决方案的一部分,并由项目通过表单和其中的自定义控件。

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

I've got a control that crashes on the form designer when I build the application, and am trying to figure out how to debug the problem.

I thought all I needed to do to be able to get in with a debugger was to start a second copy of VS and use Debug-Attach to process and attach to the copy of visual studio that the solution with my troublesome control is in. I did that but nothing is happening when the control crashes so I know I'm doing something wrong...

The crash occurs in the designer and returns the messagebox:

---------------------------
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 is part of the solution and is referenced by the project with both the form and the custom control in it.

When I dismiss the messagebox the control shows a stacktrace where the control is on my form, but since it doesn't include line numbers I don't know where the problem is coming from.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

漆黑的白昼 2024-09-26 06:11:45

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

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

    protected override void OnPaint(PaintEventArgs e) {
        if (!this.DesignMode) {
            // Runtime painting code here
            //...
        }
        base.OnPaint(e);
    }

The search path for assemblies is different when they get loaded at design time, it will be probing path for Visual Studio. Which is configured by the devenv.exe.config file in Common7\IDE. Only the Public Assemblies and Private Assemblies folders are included. The build directory of your project is not considered.

Modifying this .config file or copying your assembly into one of these folders is not exactly practical. By far the best thing to do is to just not call the code that requires this assembly at design time. Use the DesignMode property:

    protected override void OnPaint(PaintEventArgs e) {
        if (!this.DesignMode) {
            // Runtime painting code here
            //...
        }
        base.OnPaint(e);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文