AnsweredAssumed Answered

Using TableDefinition and FindField

Question asked by bulla_b on Oct 15, 2018
Latest reply on Nov 20, 2018 by john_jones-esristaff



I'm using the following code to determine if a field exists in the current layer:

var currentLayer = map.FindLayers(layer.Name).FirstOrDefault() as BasicFeatureLayer;
//Does current layer have FACILITYID field??
Boolean facID_field = false;

TableDefinition tableDef = currentLayer.GetTable().GetDefinition();
if (tableDef.FindField("FACILITYID") >= 0)
      facID_field = true;


When I do not have a Join setup on the layer everything is fine, but with a Join I will get an "InvalidOperationException" error on the TableDefinition line of code:


An exception of type 'System.InvalidOperationException' occurred in ArcGIS.Core.dll but was not handled in user code

Additional information: The dataset 'SAN_Manhole_MH_dbf' does not have a valid definition.


In this case, the layername is 'SAN_Manhole' and the joined table is 'MH_dbf'.


Is there another way I should be looking for fields in a layer??  Or is there just an issue with Joined layers going on in the background.