Select to view content in your preferred language

ArcObjects - Error accessing Feature Shape in a console application when using QueryFilter with SubFields

2011
1
Jump to solution
10-16-2018 05:48 AM
MaximeDemers
Frequent Contributor

I have the following error when I try accessing the Shape of a Feature in a console application when using a QueryFilter with SubFields.  I am using ArcObjects SDK v10.3 and Visual Studio Express 2012.

The element '{http://schemas.microsoft.com/windows/2005/02/color/WcsCommonProfileTypes}Text' is used but not declared in DTD/schema.
The thread '<No Name>' (0x12f8) has exited with code 0 (0x0).

The Exception is thrown when I do IGeometry geometry = feature.Shape; in the following code.

However if I comment the line where I declare queryFilter.SubFields = "CD_CS_FRA, NOM_OFFCL_CS_FRA";  there is no error.

Edit: Using the debugger I can see this:

using System;
using System.Collections.Generic;
using System.Text;
using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.esriSystem;


namespace DesktopConsoleApplication1
{
    class Program
    {
        private static LicenseInitializer m_AOLicenseInitializer = new DesktopConsoleApplication1.LicenseInitializer();
    
        [STAThread()]
        static void Main(string[] args)
        {
            //ESRI License Initializer generated code.
            m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeStandard }, new esriLicenseExtensionCode[] { });
            //ESRI License Initializer generated code.
            //Do not make any call to ArcObjects after ShutDownApplication()

            IWorkspace gdbWorkspace = FileGdbWorkspaceFromPath(@"\\vnageop1\geod\Maxime\test.gdb");
            IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)gdbWorkspace;
            IFeatureClass featureClass = featureWorkspace.OpenFeatureClass("GEO09E01_CS_FRA_GEN");

            IQueryFilter queryFilter = new QueryFilterClass();
            queryFilter.SubFields = "CD_CS_FRA, NOM_OFFCL_CS_FRA";
            queryFilter.WhereClause = "CD_CS_FRA = '711000'";


            using (ComReleaser comReleaser = new ComReleaser())
            {
                IFeatureCursor cursor = featureClass.Search(queryFilter, false);
                comReleaser.ManageLifetime(cursor);
                IFeature feature = null;
                while ((feature = cursor.NextFeature()) != null)
                {
                    //this line below throw the Exception
                    IGeometry geometry = feature.Shape;

                    String cdCs = Convert.ToString(feature.Value[cdCsIdx]);
                    String nom = Convert.ToString(feature.Value[nomIdx]);
                    Console.WriteLine("{0} - {1}", cdCs, nom);
                }
            }

            Console.ReadLine();
            m_AOLicenseInitializer.ShutdownApplication();
        }


        public static IWorkspace FileGdbWorkspaceFromPath(String path)
        {
            Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
            IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
            return workspaceFactory.OpenFromFile(path, 0);
        }
    }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
1 Solution

Accepted Solutions
JeffMatson
Frequent Contributor

You just need to add "SHAPE" to your list of fields specified in .SubFields

View solution in original post

1 Reply
JeffMatson
Frequent Contributor

You just need to add "SHAPE" to your list of fields specified in .SubFields