InvalidArgument=Value of '0' is not valid for 'SelectedIndex'

  • Thread starter Thread starter In10sity70
  • Start date Start date
I

In10sity70

Guest
All,

I got a new workstation. I installed VS 2012 (same version as my old workstation v4.5). I copied the project to the new machine and opened it. I ran it (before compile) with seemingly no issues. So, I compiled it. I tried to open it on the same machine and I received the following unhandled exception error...

InvalidArgument=Value of '0' is not valid for 'SelectedIndex'

I have attached the entire unhandled exception error that I am getting on the new machine, as well as the problem code. This did not happen on my old workstation. So, I went to see if there were any version differences between my old workstation and the new one and low and behold Microsoft updated .net from 4.5.1 to 4.5.2.

What I am trying to do is set every combo box to selected index of 0 when the form loads. The funny thing is that even after the unhandled error (which never happened in v4.5.1) all the combo boxes are set to index 0. So, the code works perfectly. Why? Is there a way to code around this problem in v4.5.2? Also, if I keep developing using 4.5.2 won't all my users have to update to .net 4.5.2 as well?

James

Private Sub frmConfigTool_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Users cannot input to the text box
'I do this to select cmb index on form load istead of leaving all cmb boxes blank
For Each cmb As ComboBox In GetControlsOfType(Of ComboBox)(Me, True)
cmb.SelectedIndex = 0
Next
End Sub
Function GetControlsOfType(Of ctrlType As Control)(parent As Control, searchContainers As Boolean) As IEnumerable(Of ctrlType)
Dim ctrls As New List(Of ctrlType)
For Each ctrl As Control In parent.Controls
If TypeOf ctrl Is ctrlType Then ctrls.Add(DirectCast(ctrl, ctrlType))
If searchContainers AndAlso ctrl.Controls.Count > 0 Then ctrls.AddRange(GetControlsOfType(Of ctrlType)(ctrl, searchContainers))
Next
Return ctrls
End Function


See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.ArgumentOutOfRangeException: InvalidArgument=Value of '0' is not valid for 'SelectedIndex'.
Parameter name: SelectedIndex
at System.Windows.Forms.ComboBox.set_SelectedIndex(Int32 value)
at Configuration_Tool.frmDefenseProConfigTool.frmLoad(Object sender, EventArgs e)
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.34209 built by: FX452RTMGDR
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
DefensePro Configuration Tool
Assembly Version: 2.0.0.8
Win32 Version: 2.0.0.8
CodeBase: file:///C:/Users/jamesmg/AppData/Local/Apps/2.0/70X1G199.Y89/YOKLBV32.8TL/defe..tion_0000000000000000_0002.0000_38627c26b1401d4d/DefensePro%20Configuration%20Tool.exe
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 10.0.0.0
Win32 Version: 12.0.51209.34209 built by: FX452RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.34238 built by: FX452RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Core
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.34209 built by: FX452RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.34209 built by: FX452RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.34209 built by: FX452RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Runtime.Remoting
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.34245 built by: FX452RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Remoting/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
System.Configuration
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.34209 built by: FX452RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.34234 built by: FX452RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

Continue reading...
 
Back
Top