AnsweredAssumed Answered

C# Casting from dynamic

Question asked by Philip Siekierski on Jul 2, 2020
Latest reply on Jul 2, 2020 by Artem Taturevych

Hello,

 

I am having issues everywhere with type casting. I am following the API examples from the documentation, but it doesn't seem to work for even the most basic casts.

 

An example:

 

Edge selEdge = SolidworksTools.Interaction.SelectEdge()       //my personal function, works fine, allows you select an edge
CoEdge[] coEdges = (CoEdge[])selEdge.GetCoEdges();      //fails. 'Unable to cast object of type 'System.Object[]' to type 'SolidWorks.Interop.sldworks.CoEdge[]'.'

 

I don't get it. This follows the convention given in the documentation, and is the correct return type, as per the documentation as well. What am I doing wrong?

 

Thanks,

 

Philip

 

Edit -- I see this only is an issue for arrays. Is this normal? I have a backup method to enumerate through the object[] collection and cast each individually. Is this expected behaviour?

Outcomes