我有一个基于 WinForms 的应用程序。它编译和运行完美。
问题是,从昨天开始,我无法打开主窗体的设计器文件。
起初我以为这是由于我添加了以下调用:
StyleManager.Load("some isl file");
我删除了它,撤消了对文件的更改,什么也没有。
我得到的错误是来自 XmlDocument.LoadXml()
调用的“根元素丢失”。 source 是一种实际尝试加载 xml 文件的方法,但仅在运行时这样做。
如果我忽略此消息,我会收到“对象引用未设置到对象的实例”错误,如果忽略此消息,我会收到“设计器已加载”。
更新
如果我注释掉应该读取 xml 的方法的委托(delegate)注册(在 InitializeComponent()
中),问题就不会发生。
我们在我们的解决方案中使用了 Infragistics,并且在堆栈跟踪中提到了它们。
at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.ThrowWithoutLineInfo(String res) at System.Xml.XmlTextReaderImpl.ParseDocumentContent() at System.Xml.XmlTextReaderImpl.Read() at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at System.Xml.XmlDocument.LoadXml(String xml) at MyApp.Utilities.Xml.Load(String str) at Editor.Editor.tabFlowView_ActiveTabChanged(Object sender, ActiveTabChangedEventArgs e) at Infragistics.Win.UltraWinTabControl.UltraTabControlBase.OnActiveTabChanged(ActiveTabChangedEventArgs e) at Infragistics.Win.UltraWinTabControl.UltraTabControlBase.RaiseEvent(UltraTabControlEventId id, EventArgs e) at Infragistics.Win.UltraWinTabControl.UltraTabControlBase.set_ActiveTab(UltraTab value) at Infragistics.Win.UltraWinTabControl.UltraTabControlBase.OnManagerSelectedTabItemChanging(Object sender, SelectedTabItemChangingEventArgs e) at Infragistics.Win.UltraWinTabs.TabManager.set_SelectedTabItem(ITabItem value) at Infragistics.Win.UltraWinTabControl.UltraTabControlBase.SetSelectedTab(UltraTab tab) at Infragistics.Win.UltraWinTabControl.UltraTabControlBase.PerformAction(UltraTabControlAction actionCode) at Infragistics.Win.UltraWinTabControl.UltraTabControlBase.PerformDelayedInitialize() at Infragistics.Win.UltraWinTabControl.UltraTabControlBase.OnCreateControl() 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(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(Control value) at System.Windows.Forms.Form.ControlCollection.Add(Control value) at System.Windows.Forms.Design.ControlDesigner.DesignerControlCollection.Add(Control c)
最佳答案
我在窗体上使用 UserControls 时尤其会发生此错误。如果您正在做一些需要“事件连接”的事情,它会抛出它无法做到的异常。
在您的情况下,它似乎正在调用 ActiveTabChanged 事件,该事件正在调用加载 xml。在加载 xml 之前添加 xml 加载调用。
if (DesignMode) return;
关于c# - VS 2008 上的 c#/.Net 3.5 设计器加载错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5014695/