The program I'm working on will be used on AutoCAD 2013 and 2002. So, what I'm doing is checking if the user has 2013 and if it is not present to try 2002. The problem comes when the code links the AcadApplication
object to the opened instance of 2002.
code:
_progID_2002 = "AutoCAD.Application.15";
_progID_2013 = "AutoCAD.Application.19";
try
{
Type acType = Type.GetTypeFromProgID(_progID_2002);
_acadApp = (AcadApplication)Activator.CreateInstance(acType, true);
}
catch
{
// Try other version, or exit
}
So this works perfectly when I use _progID_2013
. It opens AutoCAD 2013 and _acadApp
gets linked. When I try it with _progID_2002
it opens AutoCAD 2002, but when I set _acadApp
to the opened instance it throws the exception:
InvalidCastException
Unable to cast COM object of the type 'System._ComObject' to interface type
'AutoCAD.AcadApplication'. This operation failed because the QueryInterface
call on the COM component for the interface with IID '{070AA05D-DFC1-4E64-
8379-432269B48B07}' failed due to the following error: No such interface
supported (Exception from HRESULT:0x80004002 (E_NOINTERFACE)).
I've tried using both the 2000 and 2013 interop libraries with no luck.