defsoftware

IQueryFilter WhereClause causes AccessViolationException

Discussion created by defsoftware on Jun 12, 2012
Hi all,
I am developing using ArcEngine 10 sp4 in C# and have a problem trying to construct a Where clause that works in ArcMap but does not work programmatically.
The following where clause returns records in the Select by Attribute window in ArcMap:

lower(PAONNumber || ' ' || Streetname || ' ' || TownName || ' ' || Postcode)  like '%road%'


I have an ArcEngine application that opens the same mxd file, but executing the following code on the same feature layer causes an AccessViolationException "Attempted to read or write protected memory. This is often an indication that other memory is corrupt.":

            IQueryFilter queryFilter = new QueryFilterClass();

            queryFilter.WhereClause = "lower(PAONNumber || ' ' || Streetname || ' ' || TownName || ' ' || Postcode)  like '%road%'";

            IFeatureCursor curs = this.Layer.Search(queryFilter, false);
            IFeature row = null;

            int i = 0;

            while ((row = curs.NextFeature()) != null && i++ < 100)
            {
                   ... do stuff here...
            }

            // Release the feature cursor
            System.Runtime.InteropServices.Marshal.ReleaseComObject(curs);


I know that simpler Where Clauses work, but I am trying to search addresses from address point data and want the user to type "1 high street" to find records.

Can anyone help with this? Why should the Where Clause work in ArcMap but not ArcEngine? Is this a bug in the COM classes provided with ArcMap?

Thanks,
John

Outcomes