2013-06-27 12 views
5

Windows CEアプリケーションで継承されたフォームを開くときに問題が発生しています。これは私が元従業員から引き継ぐプロジェクトですが、コンパイルされたバージョンがいくつかのモバイルデバイスで動作しているので、オープンできるはずだと思います。私は正しいVSバージョン(2008年)を持っており、ソリューションのクリーニングとソリューションの再構築を試みました。ソリューションを展開するとき、それは魅力のように機能します。できるだけ早く私は、継承されたフォームのデザイナに移動しようとして、私は次のエラーを取得する:継承されたフォームでデザイナを開くときのエラー

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) 

答えて

8

あなたは、あなたの基本フォームのスタックトレースからはっきりと見ることができますロードイベントハンドラが実行されており、例外がスローされています。これは正常で、LoadやPaintのような基本フォームのイベントも設計時に実行されます。これは、WYSIWYGデザイナビューを提供します。しかし、このコードは実行時にのみ正しく動作することができます。

Control.DesignModeプロパティは、クラス内のコードが設計時に動作しているかどうかを確認するためのものです。残念ながら、それはCFで利用できないので、別のアプローチが必要です。魔法の呪文は次のようになります。

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(); 
     } 
    } 
+1

スーパービッグワークはまあまあです! –

関連する問題