I would like to use IDataStatistics:UniqueValues to iterate through a set of unique values. This worked flawlessly in VB6 and VBA but I am having a difficult time making it work in VS 2013, ArcGIS 10.3, targeting .Net 3.5.
I am following the example shown here
Debugging InvalidCastException was unhandled by user code error from ArcObjects DataStat? is a similar post with no resolution. I've already tried the suggestions provided there to no avail.
The error I get always occurs on the pEnumVar = CType(pData.UniqueValues, IEnumVariantSimple) line with Err.Description: "Unable to cast object of type 'System.Runtime.InteropServices.CustomMarshalers.EnumeratorViewOfEnumVariant' to type 'ESRI.ArcGIS.esriSystem.IEnumVariantSimple'."
I would really like to make this work rather than having to nest my loop to get the unique values the long way...
Here my code:
'pField As IField, pSelectionSet As ISelectionSet2 passed in Dim pData As IDataStatistics = New DataStatistics Dim pStatResults As IStatisticsResults Dim pEnumVar As IEnumVariantSimple Dim value As Object ... ... pSelectionSet.Search(Nothing, False, pCursor) pData = New DataStatistics pData.Field = pField.Name pData.Cursor = pCursor EnumVar = CType(pData.UniqueValues, IEnumVariantSimple) value = pEnumVar.Next Do Until IsDBNull(value) ... ...