<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:x="urn:schemas-microsoft-com:office:excel" xmlns:p="urn:schemas-microsoft-com:office:powerpoint" xmlns:a="urn:schemas-microsoft-com:office:access" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" xmlns:b="urn:schemas-microsoft-com:office:publisher" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet" xmlns:odc="urn:schemas-microsoft-com:office:odc" xmlns:oa="urn:schemas-microsoft-com:office:activation" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:q="http://schemas.xmlsoap.org/soap/envelope/" xmlns:D="DAV:" xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml" xmlns:ois="http://schemas.microsoft.com/sharepoint/soap/ois/" xmlns:dir="http://schemas.microsoft.com/sharepoint/soap/directory/" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:dsp="http://schemas.microsoft.com/sharepoint/dsp" xmlns:udc="http://schemas.microsoft.com/data/udc" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sub="http://schemas.microsoft.com/sharepoint/soap/2002/1/alerts/" xmlns:ec="http://www.w3.org/2001/04/xmlenc#" xmlns:sp="http://schemas.microsoft.com/sharepoint/" xmlns:sps="http://schemas.microsoft.com/sharepoint/soap/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:udcxf="http://schemas.microsoft.com/data/udc/xmlfile" xmlns:wf="http://schemas.microsoft.com/sharepoint/soap/workflow/" xmlns:mver="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns:mrels="http://schemas.openxmlformats.org/package/2006/relationships" xmlns:ex12t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:ex12m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:Z="urn:schemas-microsoft-com:" xmlns:st="&#1;" 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:"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;}
span.EmailStyle17
        {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'>Oh, the problem is that pyc.py doesn&#8217;t mark the thread as
STA.&nbsp; You can add this line to pyc.py right after mainMethod = &#8230;<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'>mainMethod.SetCustomAttribute(clr.GetClrType(System.STAThreadAttribute).GetConstructor(()),
System.Array[System.Byte](()))<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'>and it should work.&nbsp; We should do that by default for
winexe&#8217;s and probably offer an option to control STA/MTA for
non-WinEXEs.&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'>Thanks for reporting this.&nbsp; I&#8217;ve opened a bug (<a
href="http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=19409">http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=19409</a>)
and we can probably refresh the sample.<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>

<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>Davy Mitchell<br>
<b>Sent:</b> Saturday, November 08, 2008 1:59 PM<br>
<b>To:</b> Discussion of IronPython<br>
<b>Subject:</b> Re: [IronPython] ActiveX STA Issue in compiled Winforms EXE<o:p></o:p></span></p>

</div>

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

<p class=MsoNormal>Thanks Dino - here's the info:<o:p></o:p></p>

<div>

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

</div>

<div>

<div>

<p class=MsoNormal>Unhandled Exception: System.Threading.ThreadStateException:
ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated
because the current thread is not in a single-threaded apartment.<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at
System.Windows.Forms.WebBrowserBase..ctor(String clsidString)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at System.Windows.Forms.WebBrowser..ctor()<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at _stub_$24##21(Closure , CallSite ,
CodeContext , Object )<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at
Microsoft.Scripting.Actions.MatchCaller.Call2[T0,T1,TRet](Func`4 target,
CallSite site, Object[] args)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at
Microsoft.Scripting.Actions.CallSite`1.UpdateAndExecute(Object[] args)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at
Microsoft.Scripting.Actions.UpdateDelegates.Update2[T,T0,T1,TRet](CallSite
site, T0 arg0, T1 arg1)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at S$1.__init__$7(Closure , Object self)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at _stub_$18##15(Closure , CallSite ,
CodeContext , Object , Object )<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at Microsoft.Scripting.Actions.MatchCaller.Call3[T0,T1,T2,TRet](Func`5
target, CallSite site, Object[] args)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at
Microsoft.Scripting.Actions.CallSite`1.UpdateAndExecute(Object[] args)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at
Microsoft.Scripting.Actions.UpdateDelegates.Update3[T,T0,T1,T2,TRet](CallSite
site, T0 arg0, T1 arg1, T2 arg2)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at _stub_$17##14(Closure , CallSite ,
CodeContext , Object )<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at
Microsoft.Scripting.Actions.MatchCaller.Call2[T0,T1,TRet](Func`4 target,
CallSite site, Object[] args)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at
Microsoft.Scripting.Actions.CallSite`1.UpdateAndExecute(Object[] args)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at
Microsoft.Scripting.Actions.UpdateDelegates.Update2[T,T0,T1,TRet](CallSite
site, T0 arg0, T1 arg1)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at _stub_$16##13(Closure , CallSite ,
CodeContext , Object )<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at
Microsoft.Scripting.Actions.MatchCaller.Call2[T0,T1,TRet](Func`4 target, CallSite
site, Object[] args)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at
Microsoft.Scripting.Actions.CallSite`1.UpdateAndExecute(Object[] args)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at
Microsoft.Scripting.Actions.UpdateDelegates.Update2[T,T0,T1,TRet](CallSite
site, T0 arg0, T1 arg1)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at S$1.Initialize(Scope $scope, LanguageContext
$language)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at
Microsoft.Scripting.Runtime.OptimizedScriptCode.InvokeTarget(LambdaExpression
code, Scope scope)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at Microsoft.Scripting.ScriptCode.Run(Scope
scope)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at
IronPython.Runtime.PythonContext.CreateModule(String fileName, Scope scope, ScriptCode
scriptCode, ModuleOptions options)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at
IronPython.Runtime.PythonContext.CompileModule(String fileName, String
moduleName, SourceUnit sourceCode, ModuleOptions options, ScriptCode&amp;
scriptCode)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at
IronPython.Runtime.PythonContext.CompileModule(String fileName, String
moduleName, SourceUnit sourceCode, ModuleOptions options)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at
IronPython.Runtime.Importer.LoadFromSourceUnit(CodeContext context, SourceUnit
sourceCode, String name, String path)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at IronPython.Runtime.Importer.LoadModuleFromSource(CodeContext
context, String name, String path)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at
IronPython.Runtime.Importer.LoadFromDisk(CodeContext context, String name,
String fullName, String str)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at
IronPython.Runtime.Importer.ImportFromPathHook(CodeContext context, String
name, String fullName, List path, Func`5 defaultLoader)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at
IronPython.Runtime.Importer.ImportFromPath(CodeContext context, String name,
String fullName, List path)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at
IronPython.Runtime.Importer.ImportTopAbsolute(CodeContext context, String name)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at IronPython.Runtime.Importer.ImportModule(CodeContext
context, Object globals, String modName, Boolean bottom, Int32 level)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at
IronPython.Runtime.Builtin.__import__(CodeContext context, String name, Object
globals, Object locals, Object fromlist, Int32 level)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at _stub_$1##1(Closure , CallSite , CodeContext
, Object , String , IAttributesCollection , IAttributesCollection , PythonTuple
, Int32 )<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at
Microsoft.Scripting.Actions.MatchCaller.Call7[T0,T1,T2,T3,T4,T5,T6,TRet](Func`9
target, CallSite site, Object[] args)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at
Microsoft.Scripting.Actions.CallSite`1.UpdateAndExecute(Object[] args)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at
Microsoft.Scripting.Actions.UpdateDelegates.Update7[T,T0,T1,T2,T3,T4,T5,T6,TRet](CallSite
site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>rg6)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at IronPython.Runtime.Importer.Import(CodeContext
context, String fullName, PythonTuple from, Int32 level)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at
IronPython.Runtime.Operations.PythonOps.InitializeModule(Assembly precompiled,
String main, String[] references)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; at PythonMain.Main()<o:p></o:p></p>

</div>

</div>

<div>

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

</div>

<div>

<p class=MsoNormal>Repro code is:<o:p></o:p></p>

</div>

<div>

<div>

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

</div>

<div>

<p class=MsoNormal>import clr<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>clr.AddReference('System.Windows.Forms')<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>from System.Windows.Forms import *<o:p></o:p></p>

</div>

<div>

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

</div>

<div>

<p class=MsoNormal>class MainForm(Form):<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; &nbsp;def __init__(self):<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;self.Dock = DockStyle.Fill<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp; &nbsp; &nbsp;
&nbsp;self.Controls.Add(WebBrowser())<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>form = MainForm()<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>Application.Run(form)<o:p></o:p></p>

</div>

<div>

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

</div>

</div>

<div>

<p class=MsoNormal>Compiled with:<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>ipy pyc.py /out:wf /target:winexe /main:repro.py<o:p></o:p></p>

</div>

<div>

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

</div>

<div>

<p class=MsoNormal>-X:ExceptionDetail didn't alter the output from the exe. Run
from ipy there was no issue.<o:p></o:p></p>

</div>

<div>

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

</div>

<div>

<p class=MsoNormal>Cheers,<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal style='margin-bottom:12.0pt'>Davy<o:p></o:p></p>

<div>

<p class=MsoNormal>On Sat, Nov 8, 2008 at 5:39 PM, Dino Viehland &lt;<a
href="mailto:dinov@microsoft.com">dinov@microsoft.com</a>&gt; wrote:<o:p></o:p></p>

<p class=MsoNormal>I'd start w/ -X:ExceptionDetail to get the full stack trace.
&nbsp;Presumably there's something higher up the stack then the MatchCaller on
the stack.<o:p></o:p></p>

<div>

<div>

<p class=MsoNormal><br>
-----Original Message-----<br>
From: <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a>
[mailto:<a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a>]
On Behalf Of Davy Mitchell<br>
Sent: Saturday, November 08, 2008 6:19 AM<br>
To: Discussion of IronPython<br>
Subject: Re: [IronPython] ActiveX STA Issue in compiled Winforms EXE<br>
<br>
Hi Michael<br>
<br>
&gt;Are you doing this from a separate thread?<br>
<br>
No.<br>
<br>
It's a couple of modules deep from the 'main' script. Was going to try<br>
a single py file to repro.<br>
<br>
&gt; I assume it works fine when run uncompiled?<br>
<br>
Yep, runs great.<br>
Cheers,<br>
Davy<br>
<br>
<br>
On 11/8/08, Michael &lt;<a href="mailto:fuzzyman@gmail.com">fuzzyman@gmail.com</a>&gt;
wrote:<br>
&gt; Are you doing this from a separate thread? I assume it works fine when<br>
&gt; run uncompiled?<br>
&gt;<br>
&gt;<br>
&gt; Michael<br>
&gt;<br>
&gt; <a href="http://www.ironpythoninaction.com" target="_blank">http://www.ironpythoninaction.com</a><br>
&gt;<br>
&gt; On 8 Nov 2008, at 12:10, &quot;Davy Mitchell&quot; &lt;<a
href="mailto:daftspaniel@gmail.com">daftspaniel@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt; IPY 2.0 RC1<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; ActiveX Issue in a pyc compiled Winforms EXE which uses the<br>
&gt;&gt; WebBrowser control.<br>
&gt;&gt;<br>
&gt;&gt; Unhandled Exception: System.Threading.ThreadStateException: ActiveX<br>
&gt;&gt; control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be<br>
&gt;&gt; instantiated because the current thread is not in a single-threaded<br>
&gt;&gt; apartment.<br>
&gt;&gt; &nbsp; &nbsp;at System.Windows.Forms.WebBrowserBase..ctor(String
clsidString)<br>
&gt;&gt; &nbsp; &nbsp;at System.Windows.Forms.WebBrowser..ctor()<br>
&gt;&gt; &nbsp; &nbsp;at _stub_$643##332(Closure , CallSite , CodeContext ,
Object )<br>
&gt;&gt; &nbsp; &nbsp;at
Microsoft.Scripting.Actions.MatchCaller.Call2[T0,T1,TRet]<br>
&gt;&gt; (Func`4 target, C<br>
&gt;&gt;<br>
&gt;&gt; Help!! :-)<br>
&gt;&gt;<br>
&gt;&gt; Any thoughts before I delve further into this?<br>
&gt;&gt;<br>
&gt;&gt; Thanks<br>
&gt;&gt; Davy Mitchell<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Users mailing list<br>
&gt;&gt; <a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
&gt;&gt; <a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com"
target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
&gt; _______________________________________________<br>
&gt; Users mailing list<br>
&gt; <a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
&gt; <a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com"
target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
&gt;<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com">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><br>
<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com">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>

</div>

</div>

</div>

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

</div>

</div>

</body>

</html>