'Specified cast is not valid' error when creating rotated dimension using COM/ActiveX

I am using COM/ActiveX to add a rotated dimension but gives me an error "Specified cast is not valid". The weird thing is the dimension was actually created in the graphical screen but the object/entity was not returned successfully so I can assign a layer, or change its color.

Anyone has experienced this and any suggestion to solve this ?

Here is my code :

Comments

  • Could be a bug, but if only need to set the layer, you can try making obj a AcadEntity
  • Thank you. I tried your suggestion but needed to cast the call as well like :

    AcadEntity obj = (AcadEntity)aDoc.AddDimRotated(line1Pt, line2Pt, line3Pt, .707);

    in the end it gives me the same error "Specified cast is not valid".

    Even simply calling AddDimRotated, it's the same error

    aDoc.AddDimRotated(line1Pt, line2Pt, line3Pt, .707);