<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><!-- Template generated by Exclaimer Mail Disclaimers on 03:12:34 Monday, 14 July 2014 -->
<STYLE type=text/css>P.6bc59644-94fe-4358-8fd7-1c13c7c2d4d2 {
        MARGIN: 0cm 0cm 0pt
}
LI.6bc59644-94fe-4358-8fd7-1c13c7c2d4d2 {
        MARGIN: 0cm 0cm 0pt
}
DIV.6bc59644-94fe-4358-8fd7-1c13c7c2d4d2 {
        MARGIN: 0cm 0cm 0pt
}
TABLE.6bc59644-94fe-4358-8fd7-1c13c7c2d4d2Table {
        MARGIN: 0cm 0cm 0pt
}
DIV.Section1 {
        page: Section1
}
</STYLE>
<meta http-equiv=Content-Type content="text/html; charset=utf-8" /><meta name=Generator content="Microsoft Word 15 (filtered medium)" /><!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@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:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        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:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle19
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></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-GB link=blue vlink=purple>
<P class=6bc59644-94fe-4358-8fd7-1c13c7c2d4d2><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:EN-US'>I think I’ve found the cause of the problem. I recreate the script source and compile it within the FileSystemWatcher.Changed event. I can only assume that the file is still locked or is still being written to as this event fires - adding even a very small Thread.Sleep() seems to have fixed it.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><b><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>From:</span></b><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif"'> Jeff Hardy [mailto:jdhardy@gmail.com] <br /><b>Sent:</b> 14 July 2014 13:03<br /><b>To:</b> Andrew Stephens<br /><b>Cc:</b> ironpython-users@python.org<br /><b>Subject:</b> Re: [Ironpython-users] Recreate and compile a script in an existing engine instance?<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>Smells like a bug, because this should work. Can you open an issue (<a href="https://ironpython.codeplex.com/WorkItem/Create">https://ironpython.codeplex.com/WorkItem/Create</a>) with a minimal test case that reproduces it?<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>- Jeff<o:p></o:p></p></div></div><div><p class=MsoNormal style=margin-bottom:12.0pt><o:p> </o:p></p><div><p class=MsoNormal>On Fri, Jul 11, 2014 at 11:58 AM, Andrew Stephens <<a href="mailto:Andrew.Stephens@nu-ins.com" target="_blank">Andrew.Stephens@nu-ins.com</a>> wrote:<o:p></o:p></p><blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm"><div><div><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto>In C# I’m loading and compiling a script like this:-<o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto> <o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none><span style=font-size:9.5pt;font-family:Consolas;color:black;background:white>            _engine = </span><span style=font-size:9.5pt;font-family:Consolas;color:#2B91AF;background:white>Python</span><span style=font-size:9.5pt;font-family:Consolas;color:black;background:white>.CreateEngine();</span><o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none><span style=font-size:9.5pt;font-family:Consolas;color:black;background:white>            _scope = _engine.CreateScope();</span><o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none><span style=font-size:9.5pt;font-family:Consolas;color:black;background:white> </span><o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none><span style=font-size:9.5pt;font-family:Consolas;color:black;background:white>            _scriptSource = _engine.CreateScriptSourceFromFile(filename, Encoding.UTF7, </span><span style=font-size:9.5pt;font-family:Consolas;color:#2B91AF;background:white>SourceCodeKind</span><span style=font-size:9.5pt;font-family:Consolas;color:black;background:white>.Statements);</span><o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none><span style=font-size:9.5pt;font-family:Consolas;color:black;background:white>            _compiledScript = _scriptSource.Compile();</span><o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto> <o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto>(At some point in time my application will run the script by calling <span style=font-size:9.5pt;font-family:Consolas;color:black;background:white>_compiledScript.Execute(_scope).)</span><o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto> <o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto>I’ve also got a FileSystemWatcher watching the script file. When the file changes I recreate the ScriptSource and compile, basically executing those last two lines again. When I do this, _scriptSource.Compile() throws an ArgumentException (“Invalid argument valueParameter name: start”). The stack trace is below. It works if I re-create *<b>everything</b>* – the engine, scope, script source, compile, but this seems a bit a wasteful. Am I missing something?<o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto> <o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto>Stack trace:-<o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto>   at Microsoft.Scripting.Utils.ContractUtils.Requires(Boolean precondition, String paramName)<o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto>   at Microsoft.Scripting.SourceUnit.GetCodeLines(Int32 start, Int32 count)<o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto>   at Microsoft.Scripting.SourceUnit.GetCodeLine(Int32 line)<o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto>   at Microsoft.Scripting.SyntaxErrorException..ctor(String message, SourceUnit sourceUnit, SourceSpan span, Int32 errorCode, Severity severity)<o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto>   at Microsoft.Scripting.Hosting.ErrorListenerProxySink.Add(SourceUnit sourceUnit, String message, SourceSpan span, Int32 errorCode, Severity severity)<o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto>   at IronPython.Compiler.Parser.CreateParserWorker(CompilerContext context, PythonOptions options, Boolean verbatim)<o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto>   at IronPython.Compiler.Parser.CreateParser(CompilerContext context, PythonOptions options)<o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto>   at IronPython.Runtime.PythonContext.ParseAndBindAst(CompilerContext context)<o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto>   at IronPython.Runtime.PythonContext.CompilePythonCode(SourceUnit sourceUnit, CompilerOptions options, ErrorSink errorSink)<o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto>   at IronPython.Runtime.PythonContext.CompileSourceCode(SourceUnit sourceUnit, CompilerOptions options, ErrorSink errorSink)<o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto>   at Microsoft.Scripting.SourceUnit.Compile(CompilerOptions options, ErrorSink errorSink)<o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto>   at Microsoft.Scripting.SourceUnit.Compile(ErrorSink errorSink)<o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto>   at Microsoft.Scripting.Hosting.ScriptSource.CompileInternal(CompilerOptions compilerOptions, ErrorListener errorListener)<o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto>   at Microsoft.Scripting.Hosting.ScriptSource.Compile()<o:p></o:p></p><p class=MsoNormal style=mso-margin-top-alt:auto;mso-margin-bottom-alt:auto> <o:p></o:p></p></div><p> <o:p></o:p></p><p><b><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Andrew Stephens</span></b><o:p></o:p></p><p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Senior Software Engineer</span><o:p></o:p></p><p><b><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Nu Instruments Ltd</span></b><span style=color:#1F497D><o:p></o:p></span></p><p><span style=color:#1F497D> <o:p></o:p></span></p><table class=MsoNormalTable border=0 cellpadding=0><tr><td style="padding:.75pt .75pt .75pt .75pt"><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Email: </span></b><o:p></o:p></p></td><td style="padding:.75pt .75pt .75pt .75pt"><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><a href="mailto:Andrew.Stephens@nu-ins.com" target="_blank">Andrew.Stephens@nu-ins.com</a></span><o:p></o:p></p></td></tr><tr><td style="padding:.75pt .75pt .75pt .75pt"><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Tel: </span></b><o:p></o:p></p></td><td style="padding:.75pt .75pt .75pt .75pt"><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><a href="tel:%2B44%20%280%29%201978%20661304" target="_blank">+44 (0) 1978 661304</a></span><o:p></o:p></p></td></tr><tr><td style="padding:.75pt .75pt .75pt .75pt"><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Fax: </span></b><o:p></o:p></p></td><td style="padding:.75pt .75pt .75pt .75pt"><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><a href="tel:%2B44%20%280%29%201978%20664301" target="_blank">+44 (0) 1978 664301</a></span><o:p></o:p></p></td></tr><tr><td style="padding:.75pt .75pt .75pt .75pt"><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Web:</span></b><o:p></o:p></p></td><td style="padding:.75pt .75pt .75pt .75pt"><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><a href="http://www.nu-ins.com" target="_blank" title="">www.nu-ins.com</a></span><o:p></o:p></p></td></tr></table><p class=MsoNormal>  <o:p></o:p></p><p><img border=0 width=162 height=31 id="_x0000_i1025" src='cid:image001.png@01CF9F76.0956BB30' /><o:p></o:p></p><p> <o:p></o:p></p><p><b><span style='font-family:"Calibri","sans-serif";color:#1F497D'>Nu Instruments Ltd</span></b><span style='font-family:"Calibri","sans-serif";color:#1F497D'><br />Unit 74 Clywedog Road South<br />Wrexham Industrial Estate<br />Wrexham LL13 9XS<br />United Kingdom</span><o:p></o:p></p><p><b><span style='font-size:7.5pt;font-family:"Calibri","sans-serif";color:#1F497D'>Disclaimer</span></b><o:p></o:p></p><p><span style='font-size:7.5pt;font-family:"Calibri","sans-serif";color:#1F497D'>This message is confidential and may contain privileged information and is protected by copyright. If you are not the intended recipient you should not copy or disclose this message to anyone but should kindly notify the sender and delete the message. Opinions, conclusions and other information in this message which do not relate to the official business of Nu Instruments Ltd shall be understood as neither given nor endorsed by it. No contracts shall be concluded by means of this email. Neither the Company nor the sender accepts any responsibility or liability for any loss or damage arising from the presence of any computer virus or similar harmful code contained in this email or attachment/s.  It is your responsibility to scan this email and any attachments. The Company reserves the right to access and disclose all messages sent over its email system.</span><o:p></o:p></p><p><span style='font-size:7.5pt;font-family:"Calibri","sans-serif";color:#1F497D'>Nu Instruments Ltd is registered in England, No.: 3046042. Registered Office: Seacourt Tower, West Way, Oxford OX2 0FB. VAT No.: GB 616 3733 45</span><o:p></o:p></p></div><p class=MsoNormal style=margin-bottom:12.0pt><br /></p></blockquote></div></div></div></P>
<P class=6bc59644-94fe-4358-8fd7-1c13c7c2d4d2> </P>
<P class=6bc59644-94fe-4358-8fd7-1c13c7c2d4d2><span style='font-family:Calibri; font-size:11pt; color: #1F497D; font-weight: bold; '></span><span style='font-family:Calibri; font-size:11pt; color: #1F497D; font-weight: bold; '>Andrew </span><span style='font-family:Calibri; font-size:11pt; color: #1F497D; font-weight: bold; '>Stephens</span></P>
<P class=6bc59644-94fe-4358-8fd7-1c13c7c2d4d2><span style='font-family:Calibri; font-size:11pt; color: #1F497D; '>Senior Software Engineer</span></P><FONT color=#1f497d size=2>
<P class=6bc59644-94fe-4358-8fd7-1c13c7c2d4d2><span style='font-family:Calibri; font-size:11pt; color: #1F497D; font-weight: bold; '>Nu Instruments Ltd</span></P>
<P class=6bc59644-94fe-4358-8fd7-1c13c7c2d4d2> </P>
<P class=6bc59644-94fe-4358-8fd7-1c13c7c2d4d2><table class=6bc59644-94fe-4358-8fd7-1c13c7c2d4d2Table><tr><td><span style='font-family:Calibri; font-size:x-small; color: #1F497D; font-weight: bold; '>Email: </span></td><td><span style='font-family:Calibri; font-size:x-small; color: #1F497D; text-decoration: none; '>Andrew.Stephens@nu-ins.com</span></td></tr><tr><td><span style='font-family:Calibri; font-size:x-small; color: #1F497D; font-weight: bold; '>Tel: </span></td><td><span style='font-family:Calibri; font-size:x-small; color: #1F497D; '>+44 (0) 1978 661304</span></td></tr><tr><td><span style='font-family:Calibri; font-size:x-small; color: #1F497D; font-weight: bold; '>Fax: </span></td><td><span style='font-family:Calibri; font-size:x-small; color: #1F497D; '>+44 (0) 1978 664301</span></td></tr><tr><td><span style='font-family:Calibri; font-size:x-small; color: #1F497D; font-weight: bold; '>Web:</span></td><td><span style='font-family:Calibri; font-size:x-small; color: #1F497D; '><a href='http://www.nu-ins.com' title='' target=''>www.nu-ins.com</a></span></td></tr></table></P>
<P class=6bc59644-94fe-4358-8fd7-1c13c7c2d4d2></FONT> </P>
<P class=6bc59644-94fe-4358-8fd7-1c13c7c2d4d2><img border=0 width=162 height=31 src='cid:1ef635.png@70ebec31.41a4999b' /></P>
<P class=6bc59644-94fe-4358-8fd7-1c13c7c2d4d2><FONT size=2><FONT face=Calibri><FONT color=#1f497d><B></B></FONT></FONT></FONT> </P>
<P class=6bc59644-94fe-4358-8fd7-1c13c7c2d4d2><FONT size=2><FONT color=#1f497d><FONT face=Calibri><B>Nu Instruments Ltd</B><BR />Unit 74 Clywedog Road South<BR />Wrexham 
Industrial Estate<BR />Wrexham LL13 9XS<BR />United Kingdom</FONT></FONT></FONT></P>
<P><B><FONT color=#1f497d size=1 face=Calibri>Disclaimer</FONT></B></P>
<P><FONT color=#1f497d><FONT face=Calibri><FONT size=1>This message is 
confidential and may contain privileged information and is protected by 
copyright. If you are not the intended recipient you should not copy or disclose 
this message to anyone but should kindly notify the sender and delete the 
message. Opinions, conclusions and other information in this message which do 
not relate to the official business of Nu Instruments Ltd shall be understood as 
neither given nor endorsed by it. No contracts shall be concluded by means of 
this email. Neither the Company nor the sender accepts any responsibility or 
liability for any loss or damage arising from the presence of any computer virus 
or similar harmful code contained in this email or attachment/s.  It is 
your responsibility to scan this email and any attachments. The Company reserves 
the right to access and disclose all messages sent over its email 
system.<B></B></FONT></FONT></FONT></P>
<P><FONT color=#1f497d size=1 face=Calibri>Nu Instruments Ltd is registered in 
England, No.: 3046042. Registered Office: Seacourt Tower, West Way, Oxford OX2 
0FB. VAT No.: GB 616 3733 45</FONT></P>
<P class=6bc59644-94fe-4358-8fd7-1c13c7c2d4d2><div class=WordSection1><div><div><blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm"><p class=MsoNormal style=margin-bottom:12.0pt>_______________________________________________<br />Ironpython-users mailing list<br /><a href="mailto:Ironpython-users@python.org">Ironpython-users@python.org</a><br /><a href="https://mail.python.org/mailman/listinfo/ironpython-users" target="_blank">https://mail.python.org/mailman/listinfo/ironpython-users</a><o:p></o:p></p></blockquote></div><p class=MsoNormal><o:p> </o:p></p></div></div></P></FONT></BODY></HTML>