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

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

问题描述

C#,VS2010,WinForm应用程序:

有时候,我确实有一个问题,当我打开某些控件/窗体时会收到一条错误消息.所有代码都会编译,并且应用程序可以正常运行.在设计器中打开控件会给我:

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

根据我的经验,我通常会发现代码中的某些内容没有正确初始化,例如未设置在运行时以某种方式可用的属性,但在与设计器一起打开时未设置.唯一的问题是,根本原因很难找到.

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

备注:为了清楚起见,我知道如何使用调试器;-),我不知道如何告诉VS2010的设计人员以Debug模式打开控件.

自2010年9月2日起添加:

感谢您的帮助.基本上,这是MSDN Library文章,介绍了操作方法.

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

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

现在,如果必须弄清楚如何解决符号,那么我可以解决问题.....

解决方案

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

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

查看控件中的代码,并确保只在运行时运行 的代码部分像这样包装:

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

可以通过此 MSDN库文章中的调试提示来诊断硬案例.a>.

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.

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.

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.

As of 2nd SEP 2010 added:

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

  • I have managed to set it up and run the second instance (there was not much to understand how to do it).
  • It only fails in my case, because the 2nd VS2010 instance (debugging Design Time) fails to find the symbols for my custom control. I have added the symbols manually under Debugging / symbols. No result, still "Breakpoint won't be hit because of missing symbols"

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.

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..
}

Hard cases can be diagnosed with the debugging tips in this MSDN Library article.

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

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