2011-02-16 49 views
4

我有一個基於WinForms的應用程序。它的編譯和運行非常完美。 問題是,從昨天開始,我無法打開主窗體的設計器文件。
起初我以爲這是由於我添加以下電話:設計器在VS 2008上加載c#/ .Net 3.5的錯誤

StyleManager.Load("some isl file"); 

我刪除它,我解開了更改文件,並沒有什麼。

我得到的錯誤是來自XmlDocument.LoadXml()調用的「根元素丟失」。源是實際嘗試加載xml文件的方法,但只在運行時才這樣做。

如果我忽略此消息,我會得到一個「對象引用未設置爲對象的實例」的錯誤,並且通過忽略這一點,我會得到「設計器已經加載」。

更新

如果我註釋掉的應該讀取XML(在InitializeComponent())方法的代表登記,不發生問題。

我們在我們的解決方案中使用Infragistics,並在堆棧跟蹤中提及它們。

在System.Xml.XmlTextReaderImpl.Throw(例外五) 在System.Xml.XmlTextReaderImpl.ThrowWithoutLineInfo(字符串RES) 在System.Xml.XmlTextReaderImpl.ParseDocumentContent() 在System.Xml.XmlTextReaderImpl。閱讀() 在System.Xml.XmlLoader.Load(DOC的XmlDocument,XmlReader中的讀者,布爾preserveWhitespace) 在System.Xml.XmlDocument.Load(XmlReader中讀取) 在System.Xml.XmlDocument.LoadXml(字符串XML) 在MyApp.Utilities.Xml.Load(String str) at Editor.Editor.tabFlowView_ActiveTabChanged(Object sender,ActiveTabChangedEventArgs e) at Inf ragistics.Win.UltraWinTabControl.UltraTabControlBase.OnActiveTabChanged(ActiveTabChangedEventArgs E) 在Infragistics.Win.UltraWinTabControl.UltraTabControlBase.RaiseEvent(UltraTabControlEventId ID,EventArgs的) 在Infragistics.Win.UltraWinTabControl.UltraTabControlBase.set_ActiveTab(UltraTab值) 在Infragistics的。 Win.UltraWinTabControl.UltraTabControlBase.OnManagerSelectedTabItemChanging(對象發件人,SelectedTabItemChangingEventArgs E) 在Infragistics.Win.UltraWinTabs.TabManager.set_SelectedTabItem(ITabItem值) 在Infragistics.Win.UltraWinTabControl.UltraTabControlBase.SetSelectedTab(UltraTab標籤) 在Infragistics.Win。 Infragistics.Win.UltraWinTabControl.UltraTabControlBase上的UltraWinTabControl.UltraTabControlBase.PerformAction(UltraTabControlAction actionCode) .PerformDelayedInitialize() 在Infragistics.Win.UltraWinTabControl.UltraTabControlBase.OnCreateControl() 在System.Windows.Forms.Control.CreateControl(布爾fIgnoreVisible) 在System.Windows.Forms.Control.CreateControl(布爾fIgnoreVisible) 在系統.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms。 Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control。ControlCollection.Add(控制值) 在System.Windows.Forms.Form.ControlCollection.Add(控制值) 在System.Windows.Forms.Design.ControlDesigner.DesignerControlCollection.Add(對照C)

+0

我把它調用XML有關裝載的是你自己設計的呢? – 2011-02-16 09:42:39

回答

3

我有一個表格上使用用戶控件時,尤其是這種錯誤發生。如果你正在做一些需要「主動連接」的事情,它會拋出它無法解決的異常。

在你的情況下,它似乎是調用ActiveTabChanged事件,這是調用負載XML。在加載xml加載調用之前加載xml添加之前。

if (DesignMode) return; 

DesignMode

0

是您是否使用任何第三方工具或您在工具箱中自定義的任何內容?當我更新第三方工具集或從工具箱中刪除某些東西時,我遇到了這個問題。

0

我已經看過幾次,難倒了我幾次。你是否在InitializeComponent()以外的構造函數中進行調用?

將它們移動到窗體(或Load)的Shown部分,構造函數在加載設計時被調用。 Infragistics元素有可能試圖加載尚未準備好的XML。

您的窗體中是否有任何UserControl?這些也將在設計階段針對構造者執行並造成嚴重破壞。

1

看來你要麼嘗試在窗體的構造函數中或任何子控件的構造函數中加載一些xml。在其中一個構造函數中引起的任何異常都可能導致此問題。

0

是tabFlowView_ActiveTabChanged,你的方法還是在infragistics裏面?該方法中的某些內容正在嘗試加載失敗的xml。

如果這是你的代碼,這在方法的開始,看看是否能解決它:

if (DesignMode) 
     return; 
1

如果你在表單構造有東西,它拋出一個異常,那麼你得到怪異的行爲。將InitializeComponent()保留在窗體ctor中,並且如果可能,將其餘的初始化移動到Form_Load()事件處理程序。

我看到了有關缺失根元素的錯誤。有時候人們並沒有真正閱讀例外提供的基本信息。或許可以發佈您的XML文件會有所幫助,不知是不是真的錯過了根元素:

<?xml version="1.0 .... > 
<MyRootElement> 
    <Child> 
    </Child> 
</MyRootElement>