<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@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","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Ok I took a look at this and I believe this is a CLR bug &#8211;
windbg was really just useful for showing the exception which VS wasn&#8217;t doing
for me.&nbsp; I&#8217;ve included the simple repro below which doesn&#8217;t require
IronPython.&nbsp; The issue is that when we have a dynamic method closed over the 1<sup>st</sup>
parameter the remoting stack thinks we have the wrong number of arguments.&nbsp; It
then dutifily tries to report an error but it AVs because the method has no
declaring type because it&#8217;s a dynamic method!&nbsp; So it&#8217;s a bit of a double bug.&nbsp; There&#8217;s
also the fact that the process isn&#8217;t getting ripped when this happens so
someone&#8217;s probably swallowing an exception they&#8217;re not supposed to &#8211; a triple
bug!&nbsp; <o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>I&#8217;ve sent this off to the CLR team to have them take a look.&nbsp; Unless
they have a clever workaround this like means it won&#8217;t work until the CLR is
fixed </span><span style='font-size:11.0pt;font-family:Wingdings;color:#1F497D'>L</span><span
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>using System;<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>using System.Reflection;<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>using System.Reflection.Emit;<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>using System.Globalization;<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>class Test {<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>&nbsp;&nbsp;&nbsp; delegate void MyDelegate();<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>&nbsp;&nbsp;&nbsp; <o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>&nbsp;&nbsp;&nbsp; public static void Main(string[]args) {<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DynamicMethod test = new
DynamicMethod(&quot;Hello&quot;, <o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; typeof(void), <o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new Type[]{typeof(string)}, <o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; typeof(string).Module);<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MethodInfo writeString =
typeof(Console).GetMethod(&quot;WriteLine&quot;, <o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new Type[]{typeof(string)});<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ILGenerator il = test.GetILGenerator(256);<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; il.Emit(OpCodes.Ldarg_0);<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; il.EmitCall(OpCodes.Call, writeString, null);<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; il.Emit(OpCodes.Ret);<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MyDelegate dlg =&nbsp; (MyDelegate)
test.CreateDelegate(typeof(MyDelegate), &quot;Hello World!&quot;);<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dlg.BeginInvoke(new AsyncCallback(Finished), null);<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.ReadLine();<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>&nbsp;&nbsp;&nbsp; }<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>&nbsp;&nbsp;&nbsp; public static void Finished(IAsyncResult ar) {<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>&nbsp;&nbsp;&nbsp; }<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>}<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>

<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> users-bounces@lists.ironpython.com
[mailto:users-bounces@lists.ironpython.com] <b>On Behalf Of </b>Matthew Barnard<br>
<b>Sent:</b> Wednesday, May 14, 2008 1:01 AM<br>
<b>To:</b> Discussion of IronPython<br>
<b>Subject:</b> Re: [IronPython] System.Windows.Forms.MethodInvoker<o:p></o:p></span></p>

</div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal style='margin-bottom:12.0pt'>I spent a good amount of time
prodding like an awkward schoolboy at the framework with windbg.<br>
Everything is fine from the point of the BeginInvoke thread is created to the
point where the function is being looked up.<br>
The framework spends a good deal of time rooting around in a MethodTable and
looks up and calls a constructor for whatever it found there.<br>
This was the last thing I saw it doing before raising an Access Violation,
though I was looking at the TV whilst stepping so I'm sure I missed something
critical.<br>
And now I can sleep.<br>
<br>
<o:p></o:p></p>

<div>

<p class=MsoNormal>On Tue, May 13, 2008 at 8:41 PM, Matthew Barnard &lt;<a
href="mailto:m.stephen.barnard@gmail.com" target="_blank">m.stephen.barnard@gmail.com</a>&gt;
wrote:<o:p></o:p></p>

<p class=MsoNormal style='margin-bottom:12.0pt'>Ah- good catch Dino. Didn't see
a &quot;Started,&quot; so I failed to notice the &quot;Finished.&quot; was
actually printing ;)<br>
It appears that, as with the bit of code that provoked this test, start() is
not being executed by BeginInvoke.<br>
Thread.Sleep(20000) still drops to &quot;Finished&quot; as soon as the script
starts.<br>
<br>
And my assembly skills are nonexistant; you're on your own with windbg.<br>
<br>
<o:p></o:p></p>

<div>

<div>

<div>

<p class=MsoNormal>On Tue, May 13, 2008 at 7:05 PM, Dino Viehland &lt;<a
href="mailto:dinov@exchange.microsoft.com" target="_blank">dinov@exchange.microsoft.com</a>&gt;
wrote:<o:p></o:p></p>

</div>

</div>

<blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;
margin-left:4.8pt;margin-right:0in'>

<div>

<div>

<div>

<div>

<p><span style='font-size:11.0pt;color:#1F497D'>Where'd the call to
Console.ReadLine go?&nbsp; That's the reason you don't see Finished
printing&#8230;&nbsp; On 1.1 and 2.0B2 from the console or in a file w/ a call to
Console.ReadLine or raw_input I end up seeing finished getting printed.&nbsp;
We're simply exiting before the asynchronous operation but that doesn't fully
answer the question &#8211; started is still never printing!&nbsp; Stranger yet you
can call mi() directly showing the delegate is clearly created correctly and
working.&nbsp; Anyway, I'll have to look at it closer &#8211; it might require windbg
to figure out what's going wrong here.</span><o:p></o:p></p>

<p><span style='font-size:11.0pt;color:#1F497D'>&nbsp;</span><o:p></o:p></p>

<div style='border:none;border-top:solid windowtext 1.0pt;padding:3.0pt 0in 0in 0in;
border-color:-moz-use-text-color -moz-use-text-color'>

<p><b><span style='font-size:10.0pt'>From:</span></b><span style='font-size:
10.0pt'> <a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a>
[mailto:<a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a>]
<b>On Behalf Of </b>Matthew Barnard<br>
<b>Sent:</b> Tuesday, May 13, 2008 5:39 PM<br>
<b>To:</b> IronPython List<br>
<b>Subject:</b> [IronPython] System.Windows.Forms.MethodInvoker</span><o:p></o:p></p>

</div>

<div>

<div>

<p>&nbsp;<o:p></o:p></p>

<p>The C# sample runs as expected, displaying 'Started. Finished.', but the ipy
does nothing.<br>
Can someone enlighten me as to the difference? I assume it is something to do
with the way functions are represented in ipy vs. what methodinvoker is looking
for,<br>
but I'm honestly lost.<br>
<br>
<span style='color:#3333FF'>C#:<br>
<br>
class foo<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public void start()<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
Console.WriteLine(&quot;Started.&quot;);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Thread.Sleep(2000);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public void finish(IAsyncResult r)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
Console.WriteLine(&quot;Finished.&quot;);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp; class Program<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; static void Main(string[] args)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; foo bar = new foo();<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; MethodInvoker mi = new
MethodInvoker(bar.start);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mi.BeginInvoke(new
AsyncCallback(bar.finish), null);<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Console.ReadLine();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; }</span><br>
<br>
<br>
<span style='color:#009900'>IPY:<br>
<br>
import clr<br>
<br>
clr.AddReferenceByPartialName('System.Windows.Forms')<br>
<br>
from System import AsyncCallback<br>
from System.Threading import Thread<br>
from System.Windows.Forms import MethodInvoker<br>
<br>
class foo:<br>
&nbsp;&nbsp;&nbsp; def start(self):<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print 'Started.'<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Thread.Sleep(2000)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; def finish(self, r):<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print 'Finished.'<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
bar = foo()<br>
mi = MethodInvoker(bar.start)<br>
mi.BeginInvoke(AsyncCallback(bar.finish), None)<br>
</span><br>
<br>
___________________________<br>
Matthew Barnard<o:p></o:p></p>

</div>

</div>

</div>

</div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

</div>

<p class=MsoNormal style='margin-bottom:12.0pt'>_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com"
target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><o:p></o:p></p>

</blockquote>

</div>

<p class=MsoNormal><br>
<br clear=all>
<br>
-- <br>
___________________________<br>
<span style='color:#888888'>Matthew Barnard </span><o:p></o:p></p>

</div>

<p class=MsoNormal><br>
<br clear=all>
<br>
-- <br>
___________________________<br>
Matthew Barnard <o:p></o:p></p>

</div>

</body>

</html>