- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to work with a range of AutoCAD versions spanning from 2016 to 2019. I'm referencing the 2019 interop dll's. In the code snippet, I'm able to set a reference to a new AutoCAD instance as a dynamic data type. The issue arises when I try to cast that object into an IAcadApplication object. The issue extends when opening a document as well. I can validate the type name from the code snippet. I know it's the correct type. So, why am I receiving these errors?
Application Error: 'Autodesk.AutoCAD.Interop.IAcadApplication'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{6323190E-C6ED-434C-A368-E9314A8D7597}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).'
Document Error: Unable to cast COM object of type 'System.__ComObject' to interface type 'Autodesk.AutoCAD.Interop.IAcadDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{7F63D215-73CE-4BC0-80EA-83EBC7CFF905}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))..
public string GetTypeName(object comObject)
{
if (!(comObject is IDispatch)) return null;
var _dispatch = (IDispatch)comObject;
var pTypeInfo = _dispatch.GetTypeInfo(0, 1033);
pTypeInfo.GetDocumentation(
-1,
out var pBstrName,
out string pBstrDocString,
out int pdwHelpContext,
out var pBstrHelpFile);
string str = pBstrName;
if (str[0] == 95)
{
// remove leading '_'
str = str.Substring(1);
}
return str;
}
Solved! Go to Solution.