System.InvalidCastException

887
2
03-02-2011 08:00 AM
MarielaDel_Rio
New Contributor III
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?
0 Kudos
2 Replies
NeilClemmons
Regular Contributor III
It is saying the exception was thrown in Microsoft.VisualBasic.dll.  That means the exception is not being thrown in your code.  Also, anytime an exception is thrown you will see this "first chance exception" message in your debug window.  All this means is that an exception was thrown.  If you don't see a corresponding "second chance exception" message then that means the exception was handled by the code wherever that exception was thrown.  Since you're not seeing this second message then it's doubtful it's anything you need to worry about.
0 Kudos
MarielaDel_Rio
New Contributor III
You are right. It does not seem to be anything to worry about... just wondering.
I will go through all the "behind the scenes" code, to see if any event is causing it. For now, it works as it is.

Thanks
0 Kudos