Invalid execution context

Invalid execution context

stardust1611
Enthusiast Enthusiast
3,403 Views
4 Replies
Message 1 of 5

Invalid execution context

stardust1611
Enthusiast
Enthusiast
I'm trying to open a drawing in autocad 2010 with this line:

app.Documents.Open(filename, bool.FalseString, string.Empty);

The variables seem to be OK, but I'm still getting the following error message: "Invalid execution context".
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).
Please help.
0 Likes
3,404 Views
4 Replies
Replies (4)
Message 2 of 5

GeeHaa
Collaborator
Collaborator
I'm getting the same error. This line was working until I loaded dwgthumbnails.ocx

Dim dwg As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(listOfFiles(cnt), True)

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

I took out the references to DwgThumbNails but It still crashes

System.Runtime.InteropServices.COMException was unhandled by user code
ErrorCode=-2145386295
HelpLink="C:\Program Files\AutoCAD 2008\HELP\OLE_ERR.CHM#-2145386295"
Message="Invalid execution context"
Source="AutoCAD"
StackTrace:
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
at Autodesk.AutoCAD.ApplicationServices.DocumentCollection.Open(String fileName, Boolean forReadOnly, String password)
at Autodesk.AutoCAD.ApplicationServices.DocumentCollection.Open(String fileName, Boolean forReadOnly)
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
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(IWin32Window owner, Form formToShow, Boolean persistSizeAndPosition)
at Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(Form formToShow)
at BatchPlot_AMSTS.AMSTSCommands.PlotCurrentLayout() in C:\Documents and Settings\amasutti\My Documents\Visual Studio 2008\Projects\VbMgdAcad3\VbMgdAcad3\Commands5.vb:line 425
at AcMgCommandClass.InvokeWorker(AcMgCommandClass* , MethodInfo mi, Object commandObject, Boolean bLispFunction)
at AcMgCommandClass.InvokeWorkerWithExceptionFilter(AcMgCommandClass* , MethodInfo mi, Object commandObject, Boolean bLispFunction)
at AcMgPerDocumentCommandClass.Invoke(AcMgPerDocumentCommandClass* , gcroot<:REFLECTION::METHODINFO>* mi, Boolean bLispFunction)
at AcMgCommandClass.CommandThunk.Invoke(CommandThunk* )
InnerException:

Thanks in advance.
0 Likes
Message 3 of 5

stardust1611
Enthusiast
Enthusiast
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:
try
{
}
catch (COMException comEx)
{
}

If you do find the solution please share it with me.
0 Likes
Message 4 of 5

Anonymous
Not applicable
If the Form is modal, this will not work.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6339505@discussion.autodesk.com...
I'm getting the same error. This line was working until I loaded
dwgthumbnails.ocx Dim dwg As Document =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(listOfFiles(cnt),
True) 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 I took out the references to DwgThumbNails
but It still crashes System.Runtime.InteropServices.COMException was unhandled
by user code ErrorCode=-2145386295 HelpLink="C:\Program Files\AutoCAD
2008\HELP\OLE_ERR.CHM#-2145386295" Message="Invalid execution context"
Source="AutoCAD" StackTrace: at
System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32
errorCode, IntPtr errorInfo) at
System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode) at
Autodesk.AutoCAD.ApplicationServices.DocumentCollection.Open(String fileName,
Boolean forReadOnly, String password) at
Autodesk.AutoCAD.ApplicationServices.DocumentCollection.Open(String fileName,
Boolean forReadOnly) 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 at
System.Windows.Forms.Control.OnClick(EventArgs e) at
System.Windows.Forms.Button.OnClick(EventArgs e) at
System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at
System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32
clicks) at System.Windows.Forms.Control.WndProc(Message& m) at
System.Windows.Forms.ButtonBase.WndProc(Message& m) at
System.Windows.Forms.Button.WndProc(Message& m) at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at
System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam) at
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData) at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason,
ApplicationContext context) at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context) at System.Windows.Forms.Application.RunDialog(Form
form) at System.Windows.Forms.Form.ShowDialog(IWin32Window owner) at
Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(IWin32Window
owner, Form formToShow, Boolean persistSizeAndPosition) at
Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(Form
formToShow) at BatchPlot_AMSTS.AMSTSCommands.PlotCurrentLayout() in C:\Documents
and Settings\amasutti\My Documents\Visual Studio
2008\Projects\VbMgdAcad3\VbMgdAcad3\Commands5.vb:line 425 at
AcMgCommandClass.InvokeWorker(AcMgCommandClass* , MethodInfo mi, Object
commandObject, Boolean bLispFunction) at
AcMgCommandClass.InvokeWorkerWithExceptionFilter(AcMgCommandClass* , MethodInfo
mi, Object commandObject, Boolean bLispFunction) at
AcMgPerDocumentCommandClass.Invoke(AcMgPerDocumentCommandClass* , gcroot* mi,
Boolean bLispFunction) at AcMgCommandClass.CommandThunk.Invoke(CommandThunk* )
InnerException: Thanks in advance.
0 Likes
Message 5 of 5

Anonymous
Not applicable
You can't open a document (or switch documents) from a visible modal form.

To do that the form must be modeless.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6339602@discussion.autodesk.com...
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:
try
{
}
catch (COMException comEx)
{
}

If you do find the solution please share it with me.