billm889

Convert COM to Non-COM Object

Discussion created by billm889 on Mar 11, 2011
Latest reply on Mar 14, 2011 by billm889
In a .net web service that I'm writing, I'm having trouble converting from a COM to non COM object. The destination object is an ArcServer geometry service polygonN. The source is an IFeature. Is there some intermediate step to go through?



   Private Sub FindShape(ByRef pPolygon As my_geometry_service.PolygonN, _
                          ByVal pFeature As IFeature)

        Try
            If pFeature Is Nothing Then
                Throw New Exception("Input feature is nothing.")
            End If


            pPolygon = CType(pFeature.Shape, my_geometry_service.PolygonN) ' *** error ***


        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
    End Sub



Error Message:
Unable to cast COM object of type 'System.__ComObject' to class type 'MyProject.my_geomety_service.PolygonN'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.

Thanks in advance for any help with this.
Bill

Outcomes