Discussion created by mariela06 on Mar 2, 2011
Latest reply on Mar 2, 2011 by mariela06
I am getting "A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll" when I try to make a selection:

Dim spatialFilter As ISpatialFilter = New SpatialFilter
            With spatialFilter
                .Geometry = envelope
                .GeometryField = fLay.FeatureClass.ShapeFieldName
                .SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects
            End With
Dim featSel As IFeatureSelection = DirectCast(fLay, IFeatureSelection)

featSel.SelectFeatures(spatialFilter, esriSelectionResultEnum.esriSelectionResultNew, False)

I am making a selection on the OnMouseUp event on a customized identifyTool.

The geometry contains an envelope that came from the mxDocument.Searchtolerance and feedback.
I inspected the SpatialFilter and it has the right envelope, the whereclasue is "" and the fields are "*"
The error does not even get trapped in the Catch as an exception, and eventhough there is an error, the intended features get selected.

It doesnt even tell me what is causing the wrong casting.

Any ideas?