在继承的表单上打开设计器时出错 [英] Error when opening designer on inherited form

查看:29
本文介绍了在继承的表单上打开设计器时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows CE 应用程序中打开继承的表单时遇到问题.这是我从前员工手中接手的一个项目,但在某些移动设备上运行了编译版本,因此我认为它应该能够打开.我有正确的 VS 版本(2008)并尝试清理解决方案并重建解决方案.部署解决方案时,它就像一个魅力.一旦我尝试进入继承表单的设计器,我就会收到以下错误:

I am having trouble opening an inherited form in a Windows CE application. This is a project that I am taking over from a ex-employee, but there is compiled versions running on some mobile devices so I would assume that it should be able to open. I have the correct VS version (2008) and have tried cleaning the solution and rebuilding the solution. When deploying the solution it works like a charm. As soon as I try to go into the designer of the inherited forms, I get the following error:

To prevent possible data loss before loading the designer, the following errors must be resolved:   

Object reference not set to an instance of an object. 

堆栈跟踪:

at MyApp.frmBase.UpdateOnline() in C:\Users\Corne\Documents\Visual Studio 2008\Projects\Test\MyApp\MyApp\frmBase.cs:line 35
at MyApp.frmBase.frmBase_Load(Object sender, EventArgs e) in C:\Users\Corne\Documents\Visual Studio 2008\Projects\Test\MyApp\MyApp\frmBase.cs:line 30
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Design.DesignerFrame.Initialize(Control view)
at System.Windows.Forms.Design.DocumentDesigner.Initialize(IComponent component)
at System.Windows.Forms.Design.FormDocumentDesigner.Initialize(IComponent component)
at System.ComponentModel.Design.DesignerHost.AddToContainerPostProcess(IComponent component, String name, IContainer containerToAddTo)
at System.ComponentModel.Design.DesignerHost.Add(IComponent component, String name)
at System.ComponentModel.Design.DesignerHost.System.ComponentModel.Design.IDesignerHost.CreateComponent(Type componentType, String name)
at System.ComponentModel.Design.Serialization.DesignerSerializationManager.CreateInstance(Type type, ICollection arguments, String name, Boolean addToContainer)
at System.ComponentModel.Design.Serialization.DesignerSerializationManager.System.ComponentModel.Design.Serialization.IDesignerSerializationManager.CreateInstance(Type type, ICollection arguments, String name, Boolean addToContainer)
at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload)  

推荐答案

您可以从堆栈跟踪中清楚地看到您的基本表单的 Load 事件处理程序正在运行并抛出异常.这是正常的,基本形式中的事件(如 Load 和 Paint)也在设计时运行.它提供 WYSIWYG 设计器视图.但是,如果该代码只能在运行时正常工作,则效果会很差.

You can clearly see from the stack trace that your base form's Load event handler is running and throwing an exception. This is normal, events in the base form like Load and Paint run at design time as well. It provides the WYSIWYG designer view. This however goes poorly if that code can only work properly at runtime.

Control.DesignMode 属性旨在为您提供一种方法来检查类中的代码是否在设计时运行.不幸的是,它在 CF 中不可用,因此需要一种不同的方法.魔法咒语是这样的:

The Control.DesignMode property was meant to provide you with a way to check if the code in the the class is operating at design time. Unfortunately it is not available in CF so a different approach is needed. The magic incantation looks like this:

    private void frmBase_Load(object sender, EventArgs e) {
        if (this.Site == null || !this.Site.DesignMode) {
            // Not in design mode, okay to do dangerous stuff...
            this.UpdateOnline();
        }
    }

这篇关于在继承的表单上打开设计器时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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