Donnerstag, 27. September 2012

An error occurred creating the form. See Exception.InnerException for details.

Visual Basic / Studio Error when starting Debug (F5) System.InvalidOperationException An error occurred creating the form. See Exception.InnerException for details. The error is: Der Index lag außerhalb des Bereichs. Er muss nicht negativ und kleiner als die Auflistung sein. Parametername: index"} 


  •  Found out the reason: 


 I had created several checkboxes and the checkstate was set to true. then i made the following Sub:

Sub checkCHBSeries() 
  If chb_alba.Checked = True Then Chart_dev.Series(0).Enabled = True Else Chart_dev.Series(0).Enabled = False 
  If chb_eagle.Checked = True Then Chart_dev.Series(1).Enabled = True Else Chart_dev.Series(1).Enabled = False 
  If chb_birdie.Checked = True Then Chart_dev.Series(2).Enabled = True Else Chart_dev.Series(2).Enabled = False 
  If chb_par.Checked = True Then Chart_dev.Series(3).Enabled = True Else Chart_dev.Series(3).Enabled = False 
  If chb_bogey.Checked = True Then Chart_dev.Series(4).Enabled = True Else Chart_dev.Series(4).Enabled = False 
  If chb_dbogey.Checked = True Then Chart_dev.Series(5).Enabled = True Else Chart_dev.Series(5).Enabled = False 
  If chb_tbogey.Checked = True Then Chart_dev.Series(6).Enabled = True Else Chart_dev.Series(6).Enabled = False 
  If chb_worse.Checked = True Then Chart_dev.Series(7).Enabled = True Else Chart_dev.Series(7).Enabled = False 
End Sub

when starting the application, it was recognized that checked is true and tried to set the charts series to enabled. but the chart was not yet initialized so it couldnt enable the series.
in the forms designer.vb code the initialization of the chart_dev is behind/below the checkboxes initialization part


  • how did i find it out: 

Exception said: See Exception.InnerException for details So i choosed to see the details: Opened the Tree -> InnerException and pulled down the stacktrace -> that told me the line and the file where to look for the thing. And i got the clou.


  •  So there seemed to be at least three ways to fix that: 


  1. put the initialization of the chart above the ones of the checkboxes -> tried that, it worked 
  2. turn off the checked state (set it to false) at design time -> worked too 
  3. catch the exception in the above mentioned sub -> would surely be the best way (didnt try) :)