Bizarre Project Collapse - can't edit or add ANYTHING without compile error please help!
-
20 April 2012 16:51
Hello -
I have been developing a Visual Basic 2010 .NET GUI based control application that has been growing over the last six months into quite an albatross. Suddenly, I have reached a brick wall where I cannot even edit a text label in the GUI without the following exception at compile time (debug) :
InvalidOperation Exception was unhandled
An error occurred creating the form. See Exception.InnerException for details. The error is: Index and count must refer to a location within the string.
Parameter name: countThis is entirely code independent - it happens if I simply drag a new control onto the GUI without even any code behind it - Once it happens the project is hosed - even if I undo or remove what I did.
I have reinstalled VB from scratch on a new computer, and same problem. I am using Windows 7 and this happens with VB Express, Even with a trial version of Visual Studio Ultimate. I am completely stuck.
Someone please advise what I should do , or if no clues, how to best and most quickly get help from Microsoft, cost is not an object, this is critical to the company I work for and I am preparing for my crucifixion if I can't get over this problem. I am a relative newbie.
Thank you!!!
- Diedit oleh Winnows 20 April 2012 16:52
Semua Balasan
-
20 April 2012 22:19
You have a statement such as this
http://msdn.microsoft.com/en-us/library/ydktsz9z(v=vs.100).aspx
somewhere in a form load event (or possibly in your desiger code) that is failing because the data has not been initialised properly. You need to search the code for every occurrence of a statement that includes parameters named index and count, and make sure that when that code is executed the data is valid. Generally, code in a form load event should be simple statements setting properties and initialising variables, because errors in this part of the code can be difficult to debug.
You can try to find the line by starting the program using debug step mode.
The inner exception details should provide more information about exactly where the error is occurring. I don't know of any easy way to identify all methods that use index and count.
- Ditandai sebagai Jawaban oleh Mark Liu-lxfModerator 01 Mei 2012 5:59
- Tanda sebagai Jawaban dihapus oleh Winnows 01 Mei 2012 17:06
-
23 April 2012 19:55
Thank you very much for your reply, Acamar - I will do as you suggest - this sounds like one of those needle in a hay stack things.
One question if you venture back this way, I have a project that compiles fine until I add or edit something. Why would this not be a problem until then? It suddenly crops up if I simply edit a label on the form. How did it compile before getting this error if the problems you suggest are present? In other words, how has the form been loading properly up until the time I simply edit a label or add a control?
Also, I am not able to debug step by step as you suggest because this exception happens when I enter debug mode, before I have that opportunity.
I will post back if/when I find a problem.
RF
-
24 April 2012 3:06
A little update on this -
After editing the label that causes the compile time exception, replacing the form1.vb file with a backup will not repair the project. It still crashes during debug.
After narrowing it down, I find that I also must replace the /bin/...pdb file (Program Debug Database). I hope this is a hint, but no idea.
I literally can't change a single letter in the text of a label without this problem occurring.
RF
-
24 April 2012 19:21
Ok I'm zeroing in on this, following the "if nobody can help, or cares, help yourself philosophy"
I turned off the "Enable Just my code" and set breakpoints so that I could find where the exception was occurring.
Turns out it crashed during the InitializeComponent() routine when loading combobox1:
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
'ComboBox1
'
Me.ComboBox1.FormattingEnabled = True
Me.ComboBox1.Items.AddRange(New Object() {"Gamma 0", "Gamma 1", "Gamma 2", "Gamma 3"})
Me.ComboBox1.Location = New System.Drawing.Point(42, 131)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(79, 22)
MeComboBox1.TabIndex = 216
Me.ComboBox1.Text = "Gamma 0"
This name had been shared by other combo boxes until I renamed them so I think I confused the compiler.
References to these comboboxes are below:
Now can anyone tell me out to get out of this mess??
I may begin a new thread now that I have narrowed down the problem.
'FPGASelect
'
Me.FPGASelect.AllowDrop = True
Me.FPGASelect.BackColor = System.Drawing.Color.Ivory
Me.FPGASelect.Font = New System.Drawing.Font("Tahoma", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.FPGASelect.FormattingEnabled = True
Me.FPGASelect.Items.AddRange(New Object() {"Isolation FPGA", "Processor FPGA", "Formatter FPGA"})
Me.FPGASelect.Location = New System.Drawing.Point(351, 23)
Me.FPGASelect.MaxDropDownItems = 3
Me.FPGASelect.Name = "FPGASelect"
Me.FPGASelect.Size = New System.Drawing.Size(116, 22)
Me.FPGASelect.TabIndex = 92
Me.FPGASelect.Text = "Isolation FPGA"
'Gamma
'
Me.Gamma.FormattingEnabled = True
Me.Gamma.Location = New System.Drawing.Point(42, 132)
Me.Gamma.Name = "Gamma"
Me.Gamma.Size = New System.Drawing.Size(79, 21)
Me.Gamma.TabIndex = 217
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FPGASelect.SelectedIndexChanged
regAddr(0) = regAddr(0) And 199 'clear FPGA select bits with "11000111" mask
Select Case FPGASelect.SelectedIndex
Case 0
regAddr(0) = regAddr(0) Or 8 'select Isolation FPGA bit
Case 1
regAddr(0) = regAddr(0) Or 16 'select Processor FPGA bit
Case 2
regAddr(0) = regAddr(0) Or 32 'select Formatter FPGA bit
End Select
End Sub
Private Sub ComboBox1_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Gamma.SelectedIndexChanged
'Gamma Select
'*************************************************
' select Processor FPGA
regAddr(0) = regAddr(0) And 199 'clear FPGA select bits with "11000111" mask
regAddr(0) = regAddr(0) Or 16 'select Processor FPGA bit
FPGASelect.SelectedIndex = 1 ' set combo box to Processor FPGA
' select register 8
regAddr(1) = 8
RegisterSelect.Value = regAddr(1) ' fill text box with register value
' READ___________________________________________________________
ReadFromSystem() '(regAddr() -- outbytes(),hexString valid only if telnet)
' MODIFY __________________________________________________________
outBytes(3) = (outBytes(3) And CByte(&H3FUL)) Or (CByte(CInt(Gamma.SelectedIndex)))
' WRITE____________________________________________________________
dWord_outbytes() '(outbytes -- dWord())
WriteToSystem() '(regAddr(1), dWord() --)
outbytes_dWord()
populate() '(Outbytes --textboxes, checkboxes, dWord)
'***************************************************
End Sub
Private Sub ComboBox1_SelectedIndexChanged_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
'Gamma Select
'*************************************************
' select Processor FPGA
regAddr(0) = regAddr(0) And 199 'clear FPGA select bits with "11000111" mask
regAddr(0) = regAddr(0) Or 16 'select Processor FPGA bit
FPGASelect.SelectedIndex = 1 ' set combo box to Processor FPGA
' select register 8
regAddr(1) = 8
RegisterSelect.Value = regAddr(1) ' fill text box with register value
' READ___________________________________________________________
ReadFromSystem() '(regAddr() -- outbytes(),hexString valid only if telnet)
' MODIFY __________________________________________________________
outBytes(3) = (outBytes(3) And CByte(&H3FUL)) Or ((CByte(CInt(ComboBox1.SelectedIndex))) << 6)
' WRITE____________________________________________________________
dWord_outbytes() '(outbytes -- dWord())
WriteToSystem() '(regAddr(1), dWord() --)
outbytes_dWord()
populate() '(Outbytes --textboxes, checkboxes, dWord)
'***************************************************
End Sub
For what it's worth, groupboxes containing these comboboxes below:
'GroupBox12
'
Me.GroupBox12.BackColor = System.Drawing.Color.FromArgb(CType(CType(50, Byte), Integer), CType(CType(64, Byte), Integer), CType(CType(64, Byte), Integer))
Me.GroupBox12.Controls.Add(Me.ComboBox1)
Me.GroupBox12.Controls.Add(Me.DefaultYCbCr)
Me.GroupBox12.Controls.Add(Me.YGain)
Me.GroupBox12.Controls.Add(Me.CbGain)
Me.GroupBox12.Controls.Add(Me.CbGainControl)
Me.GroupBox12.Controls.Add(Me.CrGainControl)
Me.GroupBox12.Controls.Add(Me.YGainControl)
Me.GroupBox12.Controls.Add(Me.CrGain)
Me.GroupBox12.Controls.Add(Me.Label81)
Me.GroupBox12.Controls.Add(Me.Label82)
Me.GroupBox12.Controls.Add(Me.Label80)
Me.GroupBox12.ForeColor = System.Drawing.Color.LightCyan
Me.GroupBox12.Location = New System.Drawing.Point(15, 296)
Me.GroupBox12.Name = "GroupBox12"
Me.GroupBox12.Size = New System.Drawing.Size(272, 168)
Me.GroupBox12.TabIndex = 179
Me.GroupBox12.TabStop = False
Me.GroupBox12.Text = "Y Cr Cb Gains"'RegisterControl
'
Me.RegisterControl.BackColor = System.Drawing.Color.FromArgb(CType(CType(58, Byte), Integer), CType(CType(64, Byte), Integer), CType(CType(58, Byte), Integer))
Me.RegisterControl.Controls.Add(Me.LogReads)
Me.RegisterControl.Controls.Add(Me.RegisterSelectGroup)
Me.RegisterControl.Controls.Add(Me.FileRead)
Me.RegisterControl.Controls.Add(Me.CheckBox33)
Me.RegisterControl.Controls.Add(Me.DebugEnable)
Me.RegisterControl.Controls.Add(Me.ReadReg)
Me.RegisterControl.Controls.Add(Me.WriteReg)
Me.RegisterControl.Controls.Add(Me.FPGASelect)
Me.RegisterControl.Controls.Add(Me.RegisterDataGroup)
Me.RegisterControl.Controls.Add(Me.Label2)
Me.RegisterControl.Font = New System.Drawing.Font("Tahoma", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.RegisterControl.ForeColor = System.Drawing.Color.LightCyan
Me.RegisterControl.Location = New System.Drawing.Point(11, 158)
Me.RegisterControl.Name = "RegisterControl"
Me.RegisterControl.Size = New System.Drawing.Size(477, 217)
Me.RegisterControl.TabIndex = 94
Me.RegisterControl.TabStop = False
Me.RegisterControl.Text = "Register Data"
Me.RegisterControl.Visible = False
RF
- Diedit oleh Winnows 24 April 2012 19:23
-
24 April 2012 22:00
If you can identify the code that is causing the error, delete that code from the deigner.
Or, delete the whole combobox object from the desinger. Check that all references have been removed - it will occur in three or four places. One of them defines the object's properties and has multiple lines that must be deleted - the others are just single lines that instantiate the object and add it to the form.
-
24 April 2012 22:23
Thanks Acamar -
I'm just a little shy about doing that because I'm not experienced enough to know how to do that properly and how to correct or delete all the references without causing further damage; also wondering how VB allowed me to get into this fix in the first place by simply renaming form objects - I would like to learn from someone just what is the proper procedure is for renaming a form object from the default.
I started a new thread here, anyone that has further comment please do so there. Thanks for the help!
http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/f6aaeb26-edbe-4def-b95f-2bdcdcccef55
RF
-
26 April 2012 1:15
If you back up your desinger VB code before doing the edit, then there is no reason to be shy about making changes because you can always restore it to exaxctly what it was before you started.
The only thing to be aware of if you choose to edit the file is that you should probably avoid allowing the designer to lay out the form while there are still any errors in the code. You get plenty of warning about doing this, however, so it would be quite difficult to do it accidentally.
-
01 Mei 2012 17:05
Mods:
Although it was very helpful in finding a workaround and narrowing down the problem, and I am grateful for the help, I would not say that the above marked qualifies for an "answer" as the problem persists and is yet unexplained in this newer thread:
http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/f6aaeb26-edbe-4def-b95f-2bdcdcccef55
RF
- Diedit oleh Winnows 01 Mei 2012 17:06