[Mono-list] Problem with foreach on a SortedList

POUSSINEAU Hervé herve.poussineau@cegetel.fr
Thu, 15 May 2003 13:20:41 +0200


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C31AD4.04E8CB20
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hello,

First of all, I know that it is not the right place to send bug =
reports, but
I can't access Bugzilla at work...

I have a problem when executing this code with mono 0.24:
using System.Collections;
class Problem
{
   public static void Main(string[] args)
   {
      SortedList list =3D new SortedList();
      list.Add(list.Count, new Queue());
      list.Add(list.Count, new Hashtable());
      list.Add(list.Count, new Stack());
      foreach (DictionaryEntry de in list)
      {
         System.Console.WriteLine("Item #{0} =3D {1}", de.Key,
de.Value.GetType().FullName);
      }
   }
}
This code compiles fine with mcs 0.24 and csc 1.0

When executed with ms runtime (1.0), results are ok:
Item #0 =3D System.Collections.Queue
Item #1 =3D System.Collections.Hashtable
Item #2 =3D System.Collections.Stack

When executed with mono, a runtime error occurs (at the foreach line):
Unhandled Exception: System.InvalidCastException: Cannot cast from =
source
type to destination type
in <0x00207> 00 .Problem:Main (string[])

What am I doing wrong?

Thanks a lot for your porting of .Net technology to *nix systems

Herv=E9

------_=_NextPart_001_01C31AD4.04E8CB20
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2653.12">
<TITLE>Problem with foreach on a SortedList</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=3D2>Hello,</FONT>
</P>

<P><FONT SIZE=3D2>First of all, I know that it is not the right place =
to send bug reports, but</FONT>
<BR><FONT SIZE=3D2>I can't access Bugzilla at work...</FONT>
</P>

<P><FONT SIZE=3D2>I have a problem when executing this code with mono =
0.24:</FONT>
<BR><FONT SIZE=3D2>using System.Collections;</FONT>
<BR><FONT SIZE=3D2>class Problem</FONT>
<BR><FONT SIZE=3D2>{</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp; public static void Main(string[] =
args)</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp; {</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SortedList list =3D =
new SortedList();</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.Add(list.Count, =
new Queue());</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.Add(list.Count, =
new Hashtable());</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.Add(list.Count, =
new Stack());</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach =
(DictionaryEntry de in list)</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
System.Console.WriteLine(&quot;Item #{0} =3D {1}&quot;, de.Key,</FONT>
<BR><FONT SIZE=3D2>de.Value.GetType().FullName);</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp; }</FONT>
<BR><FONT SIZE=3D2>}</FONT>
<BR><FONT SIZE=3D2>This code compiles fine with mcs 0.24 and csc =
1.0</FONT>
</P>

<P><FONT SIZE=3D2>When executed with ms runtime (1.0), results are =
ok:</FONT>
<BR><FONT SIZE=3D2>Item #0 =3D System.Collections.Queue</FONT>
<BR><FONT SIZE=3D2>Item #1 =3D System.Collections.Hashtable</FONT>
<BR><FONT SIZE=3D2>Item #2 =3D System.Collections.Stack</FONT>
</P>

<P><FONT SIZE=3D2>When executed with mono, a runtime error occurs (at =
the foreach line):</FONT>
<BR><FONT SIZE=3D2>Unhandled Exception: System.InvalidCastException: =
Cannot cast from source</FONT>
<BR><FONT SIZE=3D2>type to destination type</FONT>
<BR><FONT SIZE=3D2>in &lt;0x00207&gt; 00 .Problem:Main =
(string[])</FONT>
</P>

<P><FONT SIZE=3D2>What am I doing wrong?</FONT>
</P>

<P><FONT SIZE=3D2>Thanks a lot for your porting of .Net technology to =
*nix systems</FONT>
</P>

<P><FONT SIZE=3D2>Herv=E9</FONT>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01C31AD4.04E8CB20--