System.ArgumentOutOfRangeException when program is deployed

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hey,
At the moment Im working on a program that can detect an USB-device when connected. Copy all the files and directories of that device to a specified folder. All of this works. I build this program, no problem there. When I run the .exe on my Windows 7 laptop
( with one partition) the program does what its supposed to do. When I test the same program on another Windows 7 laptop (with two partitions ) and a Windows vista laptop ( with two partitions ) I get this error message ( in Dutch ):

Zie het einde van dit bericht voor meer informatie over het aanroepen
van JIT-foutopsporing (Just In Time) in plaats van dit dialoogvenster.

************** Tekst van uitzondering **************

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; private <span style="color:Blue; void LoadDownloadItems()
{
_blnLoading = <span style="color:Blue; true;
lblErrorDestination.Visible = <span style="color:Blue; false;
picErrorDestination.Visible = <span style="color:Blue; false;
_intFilesCopied = 0;
_intDirectoriesCopied = 0;

VolumeDeviceClass volumeDeviceClass = <span style="color:Blue; new VolumeDeviceClass();

<span style="color:Blue; int position = -1; <span style="color:Green; // need it for control, when to stop the for-loop
<span style="color:Blue; for (<span style="color:Blue; int i = 0; i < volumeDeviceClass.Devices.Count; i++)
{
<span style="color:Blue; if (position != -1)
<span style="color:Blue; break;
<span style="color:Blue; else
{
<span style="color:Blue; string logicalDrive = ((Volume)volumeDeviceClass.Devices).LogicalDrive;

<span style="color:Blue; for (<span style="color:Blue; int j = 0; j < _alreadyConnectedVolumes.Devices.Count; j++)
{
<span style="color:Blue; if (((Volume)_alreadyConnectedVolumes.Devices).LogicalDrive != logicalDrive)
{
position = i;
<span style="color:Blue; break;
}
}
}
}
[/code]
<br/>
System.ArgumentOutOfRangeException: De index valt buiten het bereik. Deze mag niet negatief zijn en moet kleiner zijn dan de grootte van de verzameling.

Parameternaam: index
bij System.ThrowHelper.ThrowArgumentOutOfRangeException()
bij System.Collections.Generic.List`1.get_Item(Int32 index)
bij PHL___USB_tool.USBTool.LoadDownloadItems() in C:Users2930682DesktopONDERZOEK CopyFormatUSBMyProgramPHL - USB toolPHL - USB toolUSB tool.cs:regel 162
bij PHL___USB_tool.USBTool.WndProc(Message& m) in C:Users2930682DesktopONDERZOEK CopyFormatUSBMyProgramPHL - USB toolPHL - USB toolUSB tool.cs:regel 70
bij System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
bij System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bij System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Geladen assemblys **************
mscorlib
Assembly-versie: 4.0.0.0
Win32-versie: 4.0.30319.239 (RTMGDR.030319-2300)
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
PHL - USB tool
Assembly-versie: 1.0.0.0
Win32-versie: 1.0.0.0
CodeBase: file:///C:/Users/admin/Desktop/Debug/PHL%20-%20USB%20tool.exe
----------------------------------------
System.Windows.Forms
Assembly-versie: 4.0.0.0
Win32-versie: 4.0.30319.235 built by: RTMGDR
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-versie: 4.0.0.0
Win32-versie: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System
Assembly-versie: 4.0.0.0
Win32-versie: 4.0.30319.236 built by: RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
UsbConnectorClass
Assembly-versie: 1.0.0.0
Win32-versie: 1.0.0.0
CodeBase: file:///C:/Users/admin/Desktop/Debug/UsbConnectorClass.DLL
----------------------------------------
mscorlib.resources
Assembly-versie: 4.0.0.0
Win32-versie: 4.0.30319.235 (RTMGDR.030319-2300)
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/mscorlib.resources/v4.0_4.0.0.0_nl_b77a5c561934e089/mscorlib.resources.dll
----------------------------------------
System.Windows.Forms.resources
Assembly-versie: 4.0.0.0
Win32-versie: 4.0.30319.235 built by: RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms.resources/v4.0_4.0.0.0_nl_b77a5c561934e089/System.Windows.Forms.resources.dll
----------------------------------------

************** JIT-foutopsporing **************
Als u JIT-foutopsporing wilt inschakelen, moet in het configuratiebestand voor deze
toepassing of computer (machine.config) de waarde
jitDebugging in het gedeelte system.windows.forms zijn ingesteld.
De toepassing moet ook zijn gecompileerd terwijl foutopsporing
was ingeschakeld.

Bijvoorbeeld:

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

Wanneer JIT-foutopsporing is ingeschakeld, worden onverwerkte uitzonderingen
naar het JIT-foutopsporingsprogramma gestuurd dat op de computer is geregistreerd
en worden niet door dit dialoogvenster verwerkt.


When I check my source code, it seems to me that theres no mistake made. Could anyone help me?
underneed the code for line 70

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; protected <span style="color:Blue; override <span style="color:Blue; void WndProc(<span style="color:Blue; ref Message m)
{
<span style="color:Blue; if (m.Msg == Native.WM_DEVICECHANGE)
{
<span style="color:Blue; if (m.WParam.ToInt32() == Native.DBT_DEVICEARRIVAL)
{
<span style="color:Blue; if (!_blnLoading)
{
<span style="color:Blue; for (<span style="color:Blue; int i = 0; i < _alreadyConnectedVolumes.Devices.Count; i++)
MessageBox.Show(((Volume)_alreadyConnectedVolumes.Devices).LogicalDrive);

<span style="color:Blue; switch (tabControl1.SelectedIndex)
{
<span style="color:Blue; case 0: SetProgress(_lstPictures);
lblCopies.Visible = <span style="color:Blue; false;
LoadDownloadItems();
<span style="color:Blue; break;
<span style="color:Blue; case 1: SetProgress(_lstPictures2);
LoadUploadItems();
<span style="color:Blue; break;
<span style="color:Blue; case 2: SetProgress(_lstPictures3);
LoadDeleteItems();
<span style="color:Blue; break;
}
}
}
<span style="color:Blue; else <span style="color:Blue; if (m.WParam.ToInt32() == Native.DBT_DEVICEREMOVECOMPLETE)
{
_blnLoading = <span style="color:Blue; false;

_alreadyConnectedVolumes = <span style="color:Blue; null;
_alreadyConnectedVolumes = <span style="color:Blue; new VolumeDeviceClass();
}
}
<span style="color:Blue; base.WndProc(<span style="color:Blue; ref m);
}
[/code]

and the code for line 162:
What is the problem, or what did I do wrong? Can anyone please help me.
Thank, Moekemedelij

View the full article
 
Back
Top