开发者

Designer loading error with c#/.Net 3.5 on VS 2008

I have a WinForms based application. It's compiling and running perfectly. Problem is, ever since yesterday, I can't open the main form's designer file.

At first I thought that this is due to me adding the following call:

StyleManager.Load("some isl file");

I removed it, I undid changes to the file, and nothing.

The error I get is "Root element is missing" that comes from XmlDocument.LoadXml() call. The source is a method that actually tries to load an xml file, but only does so during runtime.

If I ignore this message I get an "Object reference not set to an instance of an object" error, and by ignoring this too I get "the designer is already loaded".

Update

If I comment out the delegate registration of the method that's supposed to read the xml (in InitializeComponent()), the problem does not occur.

We use Infragistics in our solution, and there's mentioning of them in the stack trace.

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.UltraTabCont开发者_如何学CrolBase.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)


I have this error happen in particular when using UserControls on a form. If you're doing something that requires an "active connection" it throws the exception that it's unable.

In your case it appears to be calling the ActiveTabChanged event, which is calling the load xml. Prior to the load the xml add prior to the xml load call.

if (DesignMode) return;

DesignMode


It seems either you are trying to load some xml in the constructor of the form or in any of the child control's constructor. Any exception caused in one of the constructors can lead to this problem.


If you have stuff in your form constructor and it throws an exception then you get weird behavior. Keep the InitializeComponent() in your form ctor and if possible move the rest of the initialization to the Form_Load() event handler.

I have seen those errors about missing root element. Sometimes one doesn't really read basic information provided by the exception. Perhaps posting your XML file would help, maybe it is really missing the root element:

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


Are you using any 3rd party tool or anything that you customized in toolbox went off? I faced this issue when I updated the third party toolset or removed something from toolbox.


I have seen this a few times and stumped me a few times. Are you making any calls from within your Constructor other than InitializeComponent()?

Move them into the Shown section of the form (or Load), the Constructor gets called when you load the design. Chances are that the Infragistics elements are trying to load XML that isn't ready.

Do you have any UserControls within your form? These also will execute against the Constructor in design-time and cause havoc.


Is tabFlowView_ActiveTabChanged, your method or is it inside infragistics? Something in that method is trying to load xml which is failing.

If it's your code, at this at the start of the method and see if that resolves it:

    if (DesignMode)
        return;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜