<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 –
windbg was really just useful for showing the exception which VS wasn’t doing
for me. I’ve included the simple repro below which doesn’t require
IronPython. 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. It
then dutifily tries to report an error but it AVs because the method has no
declaring type because it’s a dynamic method! So it’s a bit of a double bug. There’s
also the fact that the process isn’t getting ripped when this happens so
someone’s probably swallowing an exception they’re not supposed to – a triple
bug! <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'>I’ve sent this off to the CLR team to have them take a look. Unless
they have a clever workaround this like means it won’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> </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> </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> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> 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'> <o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> 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'> DynamicMethod test = new
DynamicMethod("Hello", <o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> typeof(void), <o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> 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'> 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> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> MethodInfo writeString =
typeof(Console).GetMethod("WriteLine", <o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> 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> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> 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'> 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'> 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'> 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> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> MyDelegate dlg = (MyDelegate)
test.CreateDelegate(typeof(MyDelegate), "Hello World!");<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> 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'> Console.ReadLine();<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> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> 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'> }<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> </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> </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> </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 <<a
href="mailto:m.stephen.barnard@gmail.com" target="_blank">m.stephen.barnard@gmail.com</a>>
wrote:<o:p></o:p></p>
<p class=MsoNormal style='margin-bottom:12.0pt'>Ah- good catch Dino. Didn't see
a "Started," so I failed to notice the "Finished." 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 "Finished" 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 <<a
href="mailto:dinov@exchange.microsoft.com" target="_blank">dinov@exchange.microsoft.com</a>>
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? That's the reason you don't see Finished
printing… 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.
We're simply exiting before the asynchronous operation but that doesn't fully
answer the question – started is still never printing! Stranger yet you
can call mi() directly showing the delegate is clearly created correctly and
working. Anyway, I'll have to look at it closer – 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'> </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> <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>
{<br>
public void start()<br>
{<br>
Console.WriteLine("Started.");<br>
Thread.Sleep(2000);<br>
}<br>
<br>
public void finish(IAsyncResult r)<br>
{<br>
Console.WriteLine("Finished.");<br>
}<br>
}<br>
<br>
class Program<br>
{<br>
static void Main(string[] args)<br>
{<br>
foo bar = new foo();<br>
<br>
MethodInvoker mi = new
MethodInvoker(bar.start);<br>
mi.BeginInvoke(new
AsyncCallback(bar.finish), null);<br>
<br>
Console.ReadLine();<br>
}<br>
}</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>
def start(self):<br>
print 'Started.'<br>
Thread.Sleep(2000)<br>
<br>
def finish(self, r):<br>
print 'Finished.'<br>
<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> </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>