wierd cast problem: An unhandled exception of type 'System.InvalidCastException' occurred in...

  • Thread starter Thread starter Jeroen Ceuppens
  • Start date Start date
J

Jeroen Ceuppens

Hi, i get this error:

An unhandled exception of type 'System.InvalidCastException' occurred in
AviewerV1.exe

But, I use the same code also in another programma, and there it
works!?!?!?!?!?!?!?

There error is given on:

colormapdata[z]=(byte[])myEnumerator.Current; (changing it in
colormapdata[z]=(byte[])(myEnumerator.Current); also doesn't help)

With Quickwatch:

- myEnumerator.Current {System.Array} System.Object
[0] 0 int
[1] 0 int
[2] 0 int
[3] 131 int



Rest of the code:

ArrayList arrayList;

arrayList=ReadTxtFile();

colormapdata = new byte[256][];

System.Collections.IEnumerator myEnumerator = arrayList.GetEnumerator();

int z=0;

while ( myEnumerator.MoveNext() )

{

colormapdata[z]=(byte[])myEnumerator.Current;

z++;

}



Can anybody give me hints, where the problem could be?



Thx

JEroen
 
Probably because you're trying to cast an int[] to byte[]
(this is illegal).
Try to see if in the ReadTxtFile() method you're actually
adding byte[] to the array list and not int[].

Regards,
Valentin Iliescu
-----Original Message-----
Hi, i get this error:

An unhandled exception of
type 'System.InvalidCastException' occurred in
AviewerV1.exe

But, I use the same code also in another programma, and there it
works!?!?!?!?!?!?!?

There error is given on:

colormapdata[z]=(byte[])myEnumerator.Current; (changing it in
colormapdata[z]=(byte[])(myEnumerator.Current); also doesn't help)

With Quickwatch:

- myEnumerator.Current {System.Array} System.Object
[0] 0 int
[1] 0 int
[2] 0 int
[3] 131 int



Rest of the code:

ArrayList arrayList;

arrayList=ReadTxtFile();

colormapdata = new byte[256][];

System.Collections.IEnumerator myEnumerator = arrayList.GetEnumerator();

int z=0;

while ( myEnumerator.MoveNext() )

{

colormapdata[z]=(byte[])myEnumerator.Current;

z++;

}



Can anybody give me hints, where the problem could be?



Thx

JEroen





.
 
Back
Top