Error loading constructor using C # /. NET 3.5 on VS 2008

I have a WinForms based application. It compiles and works great. The problem is that since yesterday I can’t open the main form designer.
At first I thought that this was due to the fact that I added the following call:

StyleManager.Load("some isl file"); 

I deleted it, I disabled the changes to the file and nothing.

The error I get is the “Root element is missing” which comes from the call to XmlDocument.LoadXml() . The source is a method that actually tries to load the xml file, but does it only at runtime.

If I ignore this message, I get the error "Link to an object not installed on the object instance", and, ignoring this, I get "the constructor is already loaded."

Update

If I comment on the registration of the delegate of the method that should read xml (in InitializeComponent() ), the problem does not occur.

We use Infragistics in our solution and mention them in the stack trace.

in System.Xml.XmlTextReaderImpl.Throw (exception e) in System.Xml.XmlTextReaderImpl.ThrowWithoutLineInfo (String res) in System.Xml.XmlTextReaderImpl.ParseDocumentContent () in System.Xml.XmlTextReaderImpl.Read () in System.Xml.Xml.Xml.Lml.Xml.Lml .Load (XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) in System.Xml.XmlDocument.Load (XmlReader reader) in System.Xml.XmlDocument.LoadXml (String xml) in MyApp.Utilities.Xml.Load (String str) in the editor .Editor.tabFlowView_ActiveTabChanged (object sender, ActiveTabChangedEventArgs e) in Infragistics.Win.UltraWinTabControl.UltraTabControlBase.OnActiveTabChanged (ActiveTabChangedEventArgs e) in Infragistics.Win.UltraWinTabControl.UltraTabControlBase.RaiseEvent (UltraTabControlEventId id, EventArgs e) in Infragistics.Win.UltraWinTabControl.UltraTabControlBase .set_ActiveTab (UltraTab value) in Infragistics.Win.UltraWinTabControl.UltraTabControlBase.OnManagerSelectedTabItemChanging (from ruler object, SelectedTabItemChangingEventArgs e) in Infragistics.Win.UltraWinTabs.TabManager.set_SelectedTabItem (value ITabItem) in Infragistics.Win.UltraWinTabControl.UltraTabControlBase.SetSelectedTab (UltraTab tab) in Infragistics.Win.UltraWinTabControl.UltraTabControlBase.PerformAction (UltraTabControlAction action code) in Infragistics.Win.UltraWinTabControl.UltraTabControlBase.PerformDelayedInitialize () in Infragistics.Win.UltraWinTabControl.UltraTabControlBase.OnCreateControl () in System.Windows.Forms.Control.CreateControl (BooleanreableFile.Formable.IreleableFloresFrol.Form.Fore.Forms.Fore.Forms.Fore.Forms.ForelloFognableIloryFile.ForeableFile.Fore.Forms.ForeloreFile.Fore.Forms.ForeloreFognolIgnoreFilerolIgnoreFilerolIgnoreFilerolIrolleFile.IrolimFile.IrolisFile.ForeableFile.ForelFile.FormalIfreIloreIForeIloreIfile.IfrelementI.I. ) in System.Windows.Forms.Control.CreateControl (Boolean fIgnoreVisible) in System.Windows.Forms.Control.CreateControl (Boolean fIgnoreVisible) in System.Windows.Forms.Control.CreateControl (Boolean fIgnoreVisible) in System.Windows.Forms Control.CreateControl (Boolean fIgnoreVisible) in System.Windows.Forms.Control.Cre ateControl (Boolean fIgnoreVisible) in System.Windows.Forms.Control.CreateControl () in System.Windows.Forms.Control.ControlCollection.Add (control value) in System.Windows.Forms.Form.ControlCollection.Add (control value) in System.Windows.Forms.Design.ControlDesigner.DesignerControlCollection.Add (Control c)

+4
source share
6 answers

This error occurs for me, in particular, when using UserControls in the form. If you do something that requires an “active connection”, it throws an exception that it cannot.

In your case, it raises an ActiveTabChanged event that raises the xml load. Before downloading, xml is added before the xml download call.

 if (DesignMode) return; 

Designmode

+3
source

It seems you are trying to load some xml in the form constructor or in any of the constructors of the child control. Any exception thrown by one of the constructors may lead to this problem.

+1
source

If you have material in the form constructor and it throws an exception, you get strange behavior. Save InitializeComponent () in your ctor form and, if possible, move the rest of the initialization to the Form_Load () event handler.

I saw errors related to the lack of a root element. Sometimes no one reads the basic information provided by the exception. Perhaps posting your XML file will help, maybe this is really the missing root element:

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

Are you using any third-party tool or something that you customized in the toolbar? I ran into this problem when updating a third-party toolbox or deleting something from the toolbar.

0
source

I saw this several times and turned me on several times. Are you making any calls inside your constructor other than InitializeComponent ()?

Move them to the "Shown" section of the form (or Load), the constructor is called when the design is loaded. Most likely, the elements of Infragistics are trying to load XML, which is not ready.

Do you have any UserControls in your form? They will also run against the constructor during development and cause chaos.

0
source

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

If this is your code, do so at the beginning of the method and see if it allows it:

  if (DesignMode) return; 
0
source

Source: https://habr.com/ru/post/1339964/


All Articles