IIdentifyObj.Name throws COMException

827
2
05-19-2011 01:18 PM
JackGiebler
New Contributor
I have an ArcMap extension (written in C#) that was created for 9.3 - I am testing its compatibility with version 10 as we have customers that want to upgrade. I can build the extension using Visual Studio 2008 on a machine with a clean install of ArcGIS 10. I have a  static method that gets the display value of a field for a feature using the IIdentifyObj.Name property which works fine in 9.3; in version 10 however, a COMException is thrown (error 0x80004005). Here is the code:

        /// <summary>
        /// Returns the "Display Field" string value that is shown in ArcMap
        /// when the feature is selected with a tool (such as the Identify tool).
        /// </summary>
        /// <param name="feature">The feature to retrieve the Display Field for.</param>
        /// <returns>String value of the feature's display field in ArcMap.</returns>
        public static String GetDisplayFieldValue(IFeature feature)
        {
            IFeatureIdentifyObj featureIdentifyObject = new FeatureIdentifyObjectClass();
            featureIdentifyObject.Feature = feature;
            IIdentifyObj identifyObject = featureIdentifyObject as IIdentifyObj;
            return identifyObject.Name;  // exception thrown on this line 
        }


Is there some other method to get the display value of a field that should be used in version 10?
0 Kudos
2 Replies
DuncanHornby
MVP Notable Contributor
Just a thought but is the feature object you are passing into the function actually a valid object?
0 Kudos
SebastianKrings
Occasional Contributor
Just a thought but is the feature object you are passing into the function actually a valid object?


yes, maybe your identifyObject is null, because the cast fails
you should debug it and have a look at the attributes of each object
whats about the Ifeature object comming as parameter
it could be that this isnt correct, so
featureIdentifyObject.Feature = feature;

fails
and then
= featureIdentifyObject as IIdentifyObj;
fails, too
0 Kudos