<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Invalid execution context in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/invalid-execution-context/m-p/2595766#M68117</link>
    <description>You can't open a document (or switch documents) from a visible modal form.&lt;BR /&gt;
&lt;BR /&gt;
To do that the form must be modeless.&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
&lt;STARDUST1611&gt; wrote in message news:6339602@discussion.autodesk.com...&lt;BR /&gt;
Unfortunately I didn't find the cause why this is happening. I was trying to &lt;BR /&gt;
open a drawing from inside a windows form when I was getting the error. I moved &lt;BR /&gt;
my code to the command method instead and then it worked, just as you noticed. I &lt;BR /&gt;
simply rearranged my application and cirumvented the problem. Maybe this could &lt;BR /&gt;
help you somehow: you can catch a com exception like this:&lt;BR /&gt;
try&lt;BR /&gt;
       {&lt;BR /&gt;
       }&lt;BR /&gt;
catch (COMException comEx)&lt;BR /&gt;
   {&lt;BR /&gt;
       }&lt;BR /&gt;
&lt;BR /&gt;
If you do find the solution please share it with me.&lt;/STARDUST1611&gt;</description>
    <pubDate>Fri, 19 Feb 2010 00:33:37 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2010-02-19T00:33:37Z</dc:date>
    <item>
      <title>Invalid execution context</title>
      <link>https://forums.autodesk.com/t5/net-forum/invalid-execution-context/m-p/2595762#M68113</link>
      <description>I'm trying to open a drawing in autocad 2010 with this line:&lt;BR /&gt;
&lt;BR /&gt;
 app.Documents.Open(filename, bool.FalseString, string.Empty);&lt;BR /&gt;
&lt;BR /&gt;
The variables seem to be OK, but I'm still getting the following error message: "Invalid execution context".&lt;BR /&gt;
I can't find the solution, and there is an old thread with the same question that went unanswered (http://discussion.autodesk.com/forums/thread.jspa?threadID=643681).&lt;BR /&gt;
Please help.</description>
      <pubDate>Sun, 29 Nov 2009 10:59:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/invalid-execution-context/m-p/2595762#M68113</guid>
      <dc:creator>stardust1611</dc:creator>
      <dc:date>2009-11-29T10:59:12Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid execution context</title>
      <link>https://forums.autodesk.com/t5/net-forum/invalid-execution-context/m-p/2595763#M68114</link>
      <description>I'm getting the same error. This line was working until I loaded dwgthumbnails.ocx &lt;BR /&gt;
&lt;BR /&gt;
            Dim dwg As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(listOfFiles(cnt), True) &lt;BR /&gt;
&lt;BR /&gt;
It works if I put it in my Command Subroutine. But if I put in into a form it crashes. I'm using AutoCAD 2008 &lt;BR /&gt;
&lt;BR /&gt;
I took out the references to DwgThumbNails but It still crashes &lt;BR /&gt;
&lt;BR /&gt;
System.Runtime.InteropServices.COMException was unhandled by user code &lt;BR /&gt;
  ErrorCode=-2145386295 &lt;BR /&gt;
  HelpLink="C:\Program Files\AutoCAD 2008\HELP\OLE_ERR.CHM#-2145386295" &lt;BR /&gt;
  Message="Invalid execution context" &lt;BR /&gt;
  Source="AutoCAD" &lt;BR /&gt;
  StackTrace: &lt;BR /&gt;
       at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) &lt;BR /&gt;
       at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode) &lt;BR /&gt;
       at Autodesk.AutoCAD.ApplicationServices.DocumentCollection.Open(String fileName, Boolean forReadOnly, String password) &lt;BR /&gt;
       at Autodesk.AutoCAD.ApplicationServices.DocumentCollection.Open(String fileName, Boolean forReadOnly) &lt;BR /&gt;
       at BatchPlot_AMSTS.Plot_Dialog.Plot_Click(Object sender, EventArgs e) in C:\Documents and Settings\amasutti\My Documents\Visual Studio 2008\Projects\VbMgdAcad3\VbMgdAcad3\Plot_Dialog.vb:line 87 &lt;BR /&gt;
       at System.Windows.Forms.Control.OnClick(EventArgs e) &lt;BR /&gt;
       at System.Windows.Forms.Button.OnClick(EventArgs e) &lt;BR /&gt;
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) &lt;BR /&gt;
       at System.Windows.Forms.Control.WmMouseUp(Message&amp;amp; m, MouseButtons button, Int32 clicks) &lt;BR /&gt;
       at System.Windows.Forms.Control.WndProc(Message&amp;amp; m) &lt;BR /&gt;
       at System.Windows.Forms.ButtonBase.WndProc(Message&amp;amp; m) &lt;BR /&gt;
       at System.Windows.Forms.Button.WndProc(Message&amp;amp; m) &lt;BR /&gt;
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp;amp; m) &lt;BR /&gt;
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp;amp; m) &lt;BR /&gt;
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) &lt;BR /&gt;
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp;amp; msg) &lt;BR /&gt;
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) &lt;BR /&gt;
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) &lt;BR /&gt;
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) &lt;BR /&gt;
       at System.Windows.Forms.Application.RunDialog(Form form) &lt;BR /&gt;
       at System.Windows.Forms.Form.ShowDialog(IWin32Window owner) &lt;BR /&gt;
       at Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(IWin32Window owner, Form formToShow, Boolean persistSizeAndPosition) &lt;BR /&gt;
       at Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(Form formToShow) &lt;BR /&gt;
       at BatchPlot_AMSTS.AMSTSCommands.PlotCurrentLayout() in C:\Documents and Settings\amasutti\My Documents\Visual Studio 2008\Projects\VbMgdAcad3\VbMgdAcad3\Commands5.vb:line 425 &lt;BR /&gt;
       at AcMgCommandClass.InvokeWorker(AcMgCommandClass* , MethodInfo mi, Object commandObject, Boolean bLispFunction) &lt;BR /&gt;
       at AcMgCommandClass.InvokeWorkerWithExceptionFilter(AcMgCommandClass* , MethodInfo mi, Object commandObject, Boolean bLispFunction) &lt;BR /&gt;
       at AcMgPerDocumentCommandClass.Invoke(AcMgPerDocumentCommandClass* , gcroot&lt;:REFLECTION::METHODINFO&gt;* mi, Boolean bLispFunction) &lt;BR /&gt;
       at AcMgCommandClass.CommandThunk.Invoke(CommandThunk* ) &lt;BR /&gt;
  InnerException: &lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance.&lt;/:REFLECTION::METHODINFO&gt;</description>
      <pubDate>Thu, 18 Feb 2010 14:54:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/invalid-execution-context/m-p/2595763#M68114</guid>
      <dc:creator>GeeHaa</dc:creator>
      <dc:date>2010-02-18T14:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid execution context</title>
      <link>https://forums.autodesk.com/t5/net-forum/invalid-execution-context/m-p/2595764#M68115</link>
      <description>Unfortunately I didn't find the cause why this is happening. I was trying to open a drawing from inside a windows form when I was getting the error. I moved my code to the command method instead and then it worked, just as you noticed. I simply rearranged my application and cirumvented the problem. Maybe this could help you somehow: you can catch a com exception like this: &lt;BR /&gt;
try&lt;BR /&gt;
       {&lt;BR /&gt;
       }&lt;BR /&gt;
catch (COMException comEx)&lt;BR /&gt;
   {&lt;BR /&gt;
       }&lt;BR /&gt;
&lt;BR /&gt;
If you do find the solution please share it with me.</description>
      <pubDate>Thu, 18 Feb 2010 16:44:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/invalid-execution-context/m-p/2595764#M68115</guid>
      <dc:creator>stardust1611</dc:creator>
      <dc:date>2010-02-18T16:44:19Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid execution context</title>
      <link>https://forums.autodesk.com/t5/net-forum/invalid-execution-context/m-p/2595765#M68116</link>
      <description>If the Form is modal, this will not work.&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
&lt;GEEHAA&gt; wrote in message news:6339505@discussion.autodesk.com...&lt;BR /&gt;
I'm getting the same error. This line was working until I loaded&lt;BR /&gt;
dwgthumbnails.ocx Dim dwg As Document =&lt;BR /&gt;
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(listOfFiles(cnt),&lt;BR /&gt;
True) It works if I put it in my Command Subroutine. But if I put in into a form&lt;BR /&gt;
it crashes. I'm using AutoCAD 2008 I took out the references to DwgThumbNails&lt;BR /&gt;
but It still crashes System.Runtime.InteropServices.COMException was unhandled&lt;BR /&gt;
by user code ErrorCode=-2145386295 HelpLink="C:\Program Files\AutoCAD&lt;BR /&gt;
2008\HELP\OLE_ERR.CHM#-2145386295" Message="Invalid execution context"&lt;BR /&gt;
Source="AutoCAD" StackTrace: at&lt;BR /&gt;
System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32&lt;BR /&gt;
errorCode, IntPtr errorInfo) at&lt;BR /&gt;
System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode) at&lt;BR /&gt;
Autodesk.AutoCAD.ApplicationServices.DocumentCollection.Open(String fileName,&lt;BR /&gt;
Boolean forReadOnly, String password) at&lt;BR /&gt;
Autodesk.AutoCAD.ApplicationServices.DocumentCollection.Open(String fileName,&lt;BR /&gt;
Boolean forReadOnly) at BatchPlot_AMSTS.Plot_Dialog.Plot_Click(Object sender,&lt;BR /&gt;
EventArgs e) in C:\Documents and Settings\amasutti\My Documents\Visual Studio&lt;BR /&gt;
2008\Projects\VbMgdAcad3\VbMgdAcad3\Plot_Dialog.vb:line 87 at&lt;BR /&gt;
System.Windows.Forms.Control.OnClick(EventArgs e) at&lt;BR /&gt;
System.Windows.Forms.Button.OnClick(EventArgs e) at&lt;BR /&gt;
System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at&lt;BR /&gt;
System.Windows.Forms.Control.WmMouseUp(Message&amp;amp; m, MouseButtons button, Int32&lt;BR /&gt;
clicks) at System.Windows.Forms.Control.WndProc(Message&amp;amp; m) at&lt;BR /&gt;
System.Windows.Forms.ButtonBase.WndProc(Message&amp;amp; m) at&lt;BR /&gt;
System.Windows.Forms.Button.WndProc(Message&amp;amp; m) at&lt;BR /&gt;
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp;amp; m) at&lt;BR /&gt;
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp;amp; m) at&lt;BR /&gt;
System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg,&lt;BR /&gt;
IntPtr wparam, IntPtr lparam) at&lt;BR /&gt;
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp;amp; msg) at&lt;BR /&gt;
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32&lt;BR /&gt;
dwComponentID, Int32 reason, Int32 pvLoopData) at&lt;BR /&gt;
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason,&lt;BR /&gt;
ApplicationContext context) at&lt;BR /&gt;
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,&lt;BR /&gt;
ApplicationContext context) at System.Windows.Forms.Application.RunDialog(Form&lt;BR /&gt;
form) at System.Windows.Forms.Form.ShowDialog(IWin32Window owner) at&lt;BR /&gt;
Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(IWin32Window&lt;BR /&gt;
owner, Form formToShow, Boolean persistSizeAndPosition) at&lt;BR /&gt;
Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(Form&lt;BR /&gt;
formToShow) at BatchPlot_AMSTS.AMSTSCommands.PlotCurrentLayout() in C:\Documents&lt;BR /&gt;
and Settings\amasutti\My Documents\Visual Studio&lt;BR /&gt;
2008\Projects\VbMgdAcad3\VbMgdAcad3\Commands5.vb:line 425 at&lt;BR /&gt;
AcMgCommandClass.InvokeWorker(AcMgCommandClass* , MethodInfo mi, Object&lt;BR /&gt;
commandObject, Boolean bLispFunction) at&lt;BR /&gt;
AcMgCommandClass.InvokeWorkerWithExceptionFilter(AcMgCommandClass* , MethodInfo&lt;BR /&gt;
mi, Object commandObject, Boolean bLispFunction) at&lt;BR /&gt;
AcMgPerDocumentCommandClass.Invoke(AcMgPerDocumentCommandClass* , gcroot* mi,&lt;BR /&gt;
Boolean bLispFunction) at AcMgCommandClass.CommandThunk.Invoke(CommandThunk* )&lt;BR /&gt;
InnerException: Thanks in advance.&lt;/GEEHAA&gt;</description>
      <pubDate>Fri, 19 Feb 2010 00:33:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/invalid-execution-context/m-p/2595765#M68116</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-02-19T00:33:36Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid execution context</title>
      <link>https://forums.autodesk.com/t5/net-forum/invalid-execution-context/m-p/2595766#M68117</link>
      <description>You can't open a document (or switch documents) from a visible modal form.&lt;BR /&gt;
&lt;BR /&gt;
To do that the form must be modeless.&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
&lt;STARDUST1611&gt; wrote in message news:6339602@discussion.autodesk.com...&lt;BR /&gt;
Unfortunately I didn't find the cause why this is happening. I was trying to &lt;BR /&gt;
open a drawing from inside a windows form when I was getting the error. I moved &lt;BR /&gt;
my code to the command method instead and then it worked, just as you noticed. I &lt;BR /&gt;
simply rearranged my application and cirumvented the problem. Maybe this could &lt;BR /&gt;
help you somehow: you can catch a com exception like this:&lt;BR /&gt;
try&lt;BR /&gt;
       {&lt;BR /&gt;
       }&lt;BR /&gt;
catch (COMException comEx)&lt;BR /&gt;
   {&lt;BR /&gt;
       }&lt;BR /&gt;
&lt;BR /&gt;
If you do find the solution please share it with me.&lt;/STARDUST1611&gt;</description>
      <pubDate>Fri, 19 Feb 2010 00:33:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/invalid-execution-context/m-p/2595766#M68117</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-02-19T00:33:37Z</dc:date>
    </item>
  </channel>
</rss>

