VS 2010 - 使用设计器打开用户控件/表单时出错 [英] VS 2010 - Error when opening User Control / Form with Designer

查看:23
本文介绍了VS 2010 - 使用设计器打开用户控件/表单时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#、VS2010、WinForm 应用程序:

C#, VS2010, WinForm application:

有时我确实会遇到打开某些控件/表单时收到错误消息的问题.所有代码都编译并且应用程序正常运行.在设计器中打开控件给了我:

Sometimes I do have the problem that I get an error message when opening some of my controls / forms. All code compiles and the application runs properly. Opening the control in the designer gives me:

设计器加载器没有提供根组件,但没有说明原因.

The designer loader did not provide a root component but has not indicated why.

根据我的经验,我可以说,这通常是我的代码中没有正确初始化的东西,例如未设置在运行时以某种方式可用的属性,但在使用设计器打开时不可用.唯一的问题是,根本原因很难找到.

From my experience I can tell, it is usually something in my code which does not get properly initialized, e.g. a property is not set which is somehow available at runtime, but not when opened with the designer. The only issue is, that the root cause is hard to find.

问:当设计师在 Visual Studio 2010 中打开我的组件时,是否有机会以某种方式使用调试器?这会很有帮助,而且解决问题很可能只需要几分钟.

Q: Is there a chance to somehow use the debugger when the designer opens my component in Visual Studio 2010? That would help a lot and the problem tackling is most likely a matter of minutes then.

备注:为了说明清楚,我知道如何使用调试器;-),我只是不知道如何告诉 VS2010 的设计器在调试模式下打开我的控件.

Remark: Just to make this clear, I know how to use the debugger ;-), I only have no idea how I could tell VS2010's designer to open my control in Debug mode.

截至 2010 年 9 月 2 日添加:

As of 2nd SEP 2010 added:

感谢您的帮助.基本上它是 MSDN Library 文章描述如何做到这一点.

Thanks for your help. Basically it is the MSDN Library article describing how to do it.

  • 我已成功设置并运行第二个实例(没有太多了解如何做到这一点).
  • 仅在我的情况下失败,因为第二个 VS2010 实例(调试设计时间)无法找到我的自定义控件的符号.我已经在调试/符号下手动添加了符号.不结果,仍然由于缺少符号,断点不会被命中"

顺便说一句,使用这种方法从符号加载(通过模块窗口)中排除一些东西是有帮助的,因为这样可以节省很多时间.

BTW, using this approach it is helpful to exclude some stuff from the symbol loading (via modules window), because this will safe a lot of time.

现在如果必须弄清楚如何解决符号,然后我可以解决这个问题.....

Now if have to figure out how to get the symbols resolved and then I can tackle the issue.....

推荐答案

自定义控件的绝大多数设计时问题是由事件处理程序中的代码或在设计时以及运行时运行的控件中的方法覆盖引起的.这通常是可取的,例如,当您在属性"窗口中更改属性时,您会得到即时反馈.

The vast majority of design time problems with custom controls are caused by code in the event handlers or method overrides in your control running at design time as well as run time. That's normally desirable, you get instant feedback when you change a property in the Properties window for example.

但当代码依赖于在运行时可用但在设计时不可用的东西时,这是不可取的.就像 dbase 连接或存储在 build 文件夹中的文件一样.这可能会生成异常,并且 Visual Studio 在设计时处理异常的能力不是很强.最坏的情况是,您可以在没有任何诊断的情况下将 VS 崩溃到桌面.但一切皆有可能.

But not desirable when the code depends on something that's available at runtime but not design time. Like a dbase connection or a file that's stored in the build folder. That can generate exceptions and Visual Studio isn't very robust against handling exceptions at design time. Worst case, you can crash VS to the desktop without any diagnostic. But anything is possible.

检查您的控件中的代码,并确保应该在运行时运行的代码位是这样包装的:

Review the code in your control and make sure that the bits of code that should only run at runtime are wrapped like this:

if (!DesignMode) {
    // etc..
}

可以通过这篇 MSDN 库文章中的调试提示来诊断困难案例.

这篇关于VS 2010 - 使用设计器打开用户控件/表单时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆