AutoCAD 2010/2011/2012

AutoCAD 2010/2011/2012

Reply
Active Contributor
M_Mogharabi
Posts: 26
Registered: ‎12-12-2011
Message 1 of 2 (657 Views)
Accepted Solution

Error : Exception has been thrown by the target of an invocation

657 Views, 1 Replies
01-09-2012 12:51 AM

Hi,

I have written an external application to drive autocad with a dll that was registered for COM. I have followed this codes to write my application however i have replaced the following code with AddNumbers() method:

 

public string OpenDWGFile(string MyDWGFilePath)
{
DocumentCollection dm = Application.DocumentManager; Document doc = null; if(File.Exists(MyDWGFilePath)) { doc = dm.Open(MyDWGFilePath, false); Application.DocumentManager.MdiActiveDocument = doc;
return "This file is exists";
 }
else
return "This file is not exist";
}

 but when i run my application the autocad software open and then close immediatly and this error message is shown : Exception has been thrown by the target of an invocation.

 

but if i comment the following lines of my code the application works without any errors:

 

doc = dm.Open(MyDWGFilePath, false);
Application.DocumentManager.MdiActiveDocument = doc;

 

please help me.

Active Contributor
M_Mogharabi
Posts: 26
Registered: ‎12-12-2011
Message 2 of 2 (633 Views)

Re: Error : Exception has been thrown by the target of an invocation

01-11-2012 01:51 AM in reply to: M_Mogharabi

Hi everyone,

I have solved my problem by using this updated code instead of previouse code.

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.