[Mono-list] Problem with foreach on a SortedList

Philippe Lavoie philippe.lavoie@cactus.ca
Thu, 15 May 2003 10:08:56 -0400


This is a multi-part message in MIME format.

------_=_NextPart_001_01C31AEB.863AC1A0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Looking inside SortedList.cs, I noticed that EnumeratorMode doesn't =
define a dictionary mode...

=20

            public enum EnumeratorMode : int {KEY_MODE =3D 0, =
VALUE_MODE}

=20

I think that's the problem. Not sure how to fix it. That's kind of why, =
I'm not sending a patch with a fix :-)

=20

Philippe Lavoie

 =20

-----Original Message-----
From: Philippe Lavoie=20
Sent: Thursday, May 15, 2003 9:32 AM
To: POUSSINEAU Herv=E9; mono-list@lists.ximian.com
Subject: RE: [Mono-list] Problem with foreach on a SortedList

=20

I wrote a unit test for the problem.

=20

If you look at the unit test, you'll notice  that the SortedList =
iterator should return a DictionaryEntry and not the value of the entry. =
This might be the problem. The direct access method returns the value =
and not a DictionaryEntry. See the unit test for a comparison.

=20

=20

Philippe Lavoie

=20

   Cactus Commerce           Software Developer  *  D=E9veloppeur de =
logiciels
eBusiness. All Business.          philippe.lavoie@cactuscommerce.com

 =20

-----Original Message-----
From: POUSSINEAU Herv=E9 [mailto:herve.poussineau@cegetel.fr]=20
Sent: Thursday, May 15, 2003 7:21 AM
To: 'mono-list@lists.ximian.com'
Subject: [Mono-list] Problem with foreach on a SortedList

=20

Hello,=20

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

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

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

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

What am I doing wrong?=20

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

Herv=E9=20


------_=_NextPart_001_01C31AEB.863AC1A0
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=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<meta name=3DGenerator content=3D"Microsoft Word 10 (filtered)">
<title>Problem with foreach on a SortedList</title>

<style>
<!--
 /* Font Definitions */
 @font-face
	{font-family:Wingdings;
	panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman";}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;}
p
	{margin-right:0in;
	margin-left:0in;
	font-size:12.0pt;
	font-family:"Times New Roman";}
span.emailstyle18
	{font-family:Arial;
	color:navy;}
span.EmailStyle19
	{font-family:Arial;
	color:navy;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
	{page:Section1;}
-->
</style>

</head>

<body lang=3DEN-US link=3Dblue vlink=3Dpurple>

<div class=3DSection1>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Looking inside SortedList.cs, I =
noticed
that EnumeratorMode doesn&#8217;t define a dictionary =
mode&#8230;</span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>&nbsp;</span></font></p>

<p class=3DMsoNormal style=3D'text-autospace:none'><font size=3D2 =
face=3D"Courier New"><span
style=3D'font-size:10.0pt;font-family:"Courier =
New"'>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 <font
color=3Dblue><span style=3D'color:blue'>public</span></font> <font =
color=3Dblue><span
style=3D'color:blue'>enum</span></font> EnumeratorMode : <font =
color=3Dblue><span
style=3D'color:blue'>int</span></font> {KEY_MODE =3D 0, =
VALUE_MODE}</span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>&nbsp;</span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>I think that&#8217;s the problem. =
Not sure
how to fix it. That&#8217;s kind of why, I&#8217;m not sending a patch =
with a
fix </span></font><font size=3D2 color=3Dnavy face=3DWingdings><span
style=3D'font-size:10.0pt;font-family:Wingdings;color:navy'>J</span></fon=
t></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>&nbsp;</span></font></p>

<div>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
 10.0pt;font-family:Arial;color:navy'>Philippe Lavoie</span></font></p>

<p class=3DMsoNormal><font size=3D3 color=3Dnavy face=3D"Times New =
Roman"><span
style=3D'font-size:12.0pt;color:navy'>&nbsp;&nbsp;</span></font></p>

</div>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D2 =
face=3DTahoma><span
style=3D'font-size:10.0pt;font-family:Tahoma'>-----Original =
Message-----<br>
<b><span style=3D'font-weight:bold'>From:</span></b> </span></font><font =
size=3D2
 face=3DTahoma><span =
style=3D'font-size:10.0pt;font-family:Tahoma'>Philippe =
Lavoie</span></font><font
size=3D2 face=3DTahoma><span =
style=3D'font-size:10.0pt;font-family:Tahoma'> <br>
<b><span style=3D'font-weight:bold'>Sent:</span></b> Thursday, May 15, =
2003 9:32
AM<br>
<b><span style=3D'font-weight:bold'>To:</span></b> POUSSINEAU Herv=E9; =
</span></font><font
  size=3D2 face=3DTahoma><span =
style=3D'font-size:10.0pt;font-family:Tahoma'>mono-list</span></font><fon=
t
 size=3D2 face=3DTahoma><span =
style=3D'font-size:10.0pt;font-family:Tahoma'>@lists.ximian.com</span></f=
ont><font
size=3D2 face=3DTahoma><span =
style=3D'font-size:10.0pt;font-family:Tahoma'><br>
<b><span style=3D'font-weight:bold'>Subject:</span></b> RE: [Mono-list] =
Problem
with foreach on a SortedList</span></font></p>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D3 =
face=3D"Times New Roman"><span
style=3D'font-size:12.0pt'>&nbsp;</span></font></p>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D2 =
color=3Dnavy face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial;color:navy'>I wrote a unit =
test for
the problem.</span></font></p>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D2 =
color=3Dnavy face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial;color:navy'>&nbsp;</span></fo=
nt></p>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D2 =
color=3Dnavy face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial;color:navy'>If you look at =
the unit
test, you&#8217;ll notice&nbsp; that the SortedList iterator should =
return a
DictionaryEntry and not the value of the entry. This might be the =
problem. The
direct access method returns the value and not a DictionaryEntry. See =
the unit
test for a comparison.</span></font></p>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D2 =
color=3Dnavy face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial;color:navy'>&nbsp;</span></fo=
nt></p>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D2 =
color=3Dnavy face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial;color:navy'>&nbsp;</span></fo=
nt></p>

<div>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D2 =
color=3Dnavy face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial;color:navy'>Philippe =
Lavoie</span></font></p>

<div>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D3 =
color=3Dnavy
face=3D"Times New Roman"><span =
style=3D'font-size:12.0pt;color:navy'>&nbsp;</span></font></p>

</div>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D2 =
color=3Dnavy face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial;color:navy'>&nbsp;&nbsp; =
Cactus
Commerce&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
Software
Developer&nbsp; &#8226;&nbsp; D=E9veloppeur de logiciels<br>
eBusiness. All =
Business.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a
href=3D"mailto:philippe.lavoie@cactuscommerce.com">philippe.lavoie@cactus=
commerce.com</a></span></font></p>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D3 =
color=3Dnavy
face=3D"Times New Roman"><span =
style=3D'font-size:12.0pt;color:navy'>&nbsp;&nbsp;</span></font></p>

</div>

<p class=3DMsoNormal style=3D'margin-left:1.0in'><font size=3D2 =
face=3DTahoma><span
style=3D'font-size:10.0pt;font-family:Tahoma'>-----Original =
Message-----<br>
<b><span style=3D'font-weight:bold'>From:</span></b> POUSSINEAU Herv=E9
[mailto:herve.poussineau@cegetel.fr] <br>
<b><span style=3D'font-weight:bold'>Sent:</span></b> Thursday, May 15, =
2003 7:21
AM<br>
<b><span style=3D'font-weight:bold'>To:</span></b> =
'mono-list@lists.ximian.com'<br>
<b><span style=3D'font-weight:bold'>Subject:</span></b> [Mono-list] =
Problem with
foreach on a SortedList</span></font></p>

<p class=3DMsoNormal style=3D'margin-left:1.0in'><font size=3D3 =
face=3D"Times New Roman"><span
style=3D'font-size:12.0pt'>&nbsp;</span></font></p>

<p style=3D'margin-left:1.0in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>Hello,</span></font> </p>

<p style=3D'margin-left:1.0in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>First of all, I know that it is not the right =
place to
send bug reports, but</span></font> <br>
<font size=3D2><span style=3D'font-size:10.0pt'>I can't access Bugzilla =
at work...</span></font>
</p>

<p style=3D'margin-left:1.0in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>I have a problem when executing this code =
with mono
0.24:</span></font> <br>
<font size=3D2><span style=3D'font-size:10.0pt'>using =
System.Collections;</span></font>
<br>
<font size=3D2><span style=3D'font-size:10.0pt'>class =
Problem</span></font> <br>
<font size=3D2><span style=3D'font-size:10.0pt'>{</span></font> <br>
<font size=3D2><span style=3D'font-size:10.0pt'>&nbsp;&nbsp; public =
static void
Main(string[] args)</span></font> <br>
<font size=3D2><span style=3D'font-size:10.0pt'>&nbsp;&nbsp; =
{</span></font> <br>
<font size=3D2><span =
style=3D'font-size:10.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
SortedList list =3D new SortedList();</span></font> <br>
<font size=3D2><span =
style=3D'font-size:10.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
list.Add(list.Count, new Queue());</span></font> <br>
<font size=3D2><span =
style=3D'font-size:10.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
list.Add(list.Count, new Hashtable());</span></font> <br>
<font size=3D2><span =
style=3D'font-size:10.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
list.Add(list.Count, new Stack());</span></font> <br>
<font size=3D2><span =
style=3D'font-size:10.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
foreach (DictionaryEntry de in list)</span></font> <br>
<font size=3D2><span =
style=3D'font-size:10.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
{</span></font>
<br>
<font size=3D2><span =
style=3D'font-size:10.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;
System.Console.WriteLine(&quot;Item #{0} =3D {1}&quot;, =
de.Key,</span></font> <br>
<font size=3D2><span =
style=3D'font-size:10.0pt'>de.Value.GetType().FullName);</span></font>
<br>
<font size=3D2><span =
style=3D'font-size:10.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
}</span></font>
<br>
<font size=3D2><span style=3D'font-size:10.0pt'>&nbsp;&nbsp; =
}</span></font> <br>
<font size=3D2><span style=3D'font-size:10.0pt'>}</span></font> <br>
<font size=3D2><span style=3D'font-size:10.0pt'>This code compiles fine =
with mcs
0.24 and csc 1.0</span></font> </p>

<p style=3D'margin-left:1.0in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>When executed with ms runtime (1.0), results =
are ok:</span></font>
<br>
<font size=3D2><span style=3D'font-size:10.0pt'>Item #0 =3D =
System.Collections.Queue</span></font>
<br>
<font size=3D2><span style=3D'font-size:10.0pt'>Item #1 =3D =
System.Collections.Hashtable</span></font>
<br>
<font size=3D2><span style=3D'font-size:10.0pt'>Item #2 =3D =
System.Collections.Stack</span></font>
</p>

<p style=3D'margin-left:1.0in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>When executed with mono, a runtime error =
occurs (at
the foreach line):</span></font> <br>
<font size=3D2><span style=3D'font-size:10.0pt'>Unhandled Exception:
System.InvalidCastException: Cannot cast from source</span></font> <br>
<font size=3D2><span style=3D'font-size:10.0pt'>type to destination =
type</span></font>
<br>
<font size=3D2><span style=3D'font-size:10.0pt'>in &lt;0x00207&gt; 00 =
.Problem:Main
(string[])</span></font> </p>

<p style=3D'margin-left:1.0in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>What am I doing wrong?</span></font> </p>

<p style=3D'margin-left:1.0in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>Thanks a lot for your porting of .Net =
technology to
*nix systems</span></font> </p>

<p style=3D'margin-left:1.0in'><font size=3D2 face=3D"Times New =
Roman"><span
style=3D'font-size:10.0pt'>Herv=E9</span></font> </p>

</div>

</body>

</html>
=00
------_=_NextPart_001_01C31AEB.863AC1A0--