AutoCAD OEM throws error when converting an AcadSelectionSet object into an AcadEntity object

Hello,

We seem to be having an issue with AutoCAD OEM when trying to convert an AcadSelectionSet object into an AcadEntity object, an issue that we’re not seeing in full AutoCAD.

The line that fails is:
objEntity = CType(objSelectionSet(0), AcadEntity)
where objEntity is an AcadEntity object and objSelectionSet is a collection of just one selected AcadSelectionSet object.

In full AutoCAD, the line is executed without issue and the conversion happens without incident. In OEM, the line above causes an error to be thrown “hresult e_fail has been returned from a call to a com component”.

Can anyone help or explain why there’d be a difference between full AutoCAD and OEM?

Many thanks,

Neil Sanderson

We’ve tried a couple of suggestions to alter the conversion:

  1. objEntity = DirectCast(objSelectionSet(0), AcadEntity)
    and
  2. objEntity = TryCast(objSelectionSet(0), AcadEntity)

TryCast doesn’t even complete successfully as it should return a null (Nothing) object if it fails but it can’t even manage that, instead still throwing the E_FAIL COM error.

The issue seems related to the way the selection set is indexed, use ‘Item(i)’:

The OEM environment seems a bit more sensitive in certain situations. See this topic on the Autodesk Developer forum which declares dynamic keyword may not work the same way as in vanilla AutoCAD: Solved: How to get AcadApplication from a C# assembly running in AutoCAD OEM? - Autodesk Community

1 Like