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

**URL:** <https://forum.techsoft3d.com/t/autocad-oem-throws-error-when-converting-an-acadselectionset-object-into-an-acadentity-object/730>\
**Category:** AutoCAD OEM\
**Created:** [April 5, 2022, 9:17am UTC](https://forum.techsoft3d.com/t/autocad-oem-throws-error-when-converting-an-acadselectionset-object-into-an-acadentity-object/730 "2022-04-05T09:17:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nsanderson](https://avatars.discourse-cdn.com/v4/letter/n/e274bd/32.png) [@nsanderson](https://forum.techsoft3d.com/u/nsanderson)\
**Post date:** [April 5, 2022, 9:17am UTC](https://forum.techsoft3d.com/t/autocad-oem-throws-error-when-converting-an-acadselectionset-object-into-an-acadentity-object/730/1 "2022-04-05T09:17:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nsanderson](https://avatars.discourse-cdn.com/v4/letter/n/e274bd/32.png) [@nsanderson](https://forum.techsoft3d.com/u/nsanderson)\
**Post date:** [April 12, 2022, 9:40am UTC](https://forum.techsoft3d.com/t/autocad-oem-throws-error-when-converting-an-acadselectionset-object-into-an-acadentity-object/730/2 "2022-04-12T09:40:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![paavo](https://avatars.discourse-cdn.com/v4/letter/p/b3f665/32.png) [@paavo](https://forum.techsoft3d.com/u/paavo)\
**Post date:** [May 10, 2022, 9:07am UTC](https://forum.techsoft3d.com/t/autocad-oem-throws-error-when-converting-an-acadselectionset-object-into-an-acadentity-object/730/3 "2022-05-10T09:07:59Z")

</div>

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

 ![CAP](https://us1.discourse-cdn.com/flex020/uploads/techsoft3d/original/1X/b6d681b9d7f42616b881382b565151b51af6b3c6.jpeg)

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](https://forums.autodesk.com/t5/net/how-to-get-acadapplication-from-a-c-assembly-running-in-autocad/m-p/5060852#M40792)
