AnsweredAssumed Answered

Bug in Geoprocessing.ExecuteToolAsync / management.AddField ?

Question asked by htudosieesri-ca-esridist Employee on Jul 8, 2016
Latest reply on Jul 13, 2016 by wkaiser-esristaff

In my application I have two gdb_s with two layers with the same name on the same Map.

(Don't ask me why: this is how the client wants and my project manager has enforced the specs.

Previously I have put them on separate MapViews and synchronized the views...)

I diferenciate the two layers by the presence of the db_operation field, and edit accordingly their symbology:

To a certain point, I have to check the second layer and add additional fields.

This is the code:


private async Task<bool> ExecuteAddFieldTool(KeyValuePair<string, string> field, string fieldType, int? fieldLength = null, bool isNullable = true)
                var inTable = DeltaLayer.Name;
                var workspaceName = ((IInternalMapMember)DeltaLayer).WorkspaceName;

                var parameters = Geoprocessing.MakeValueArray(inTable, field.Key, fieldType.ToUpper(), null, null,
                    fieldLength, field.Value, isNullable ? "NULABLE" : "NON_NULLABLE");
                var env = Geoprocessing.MakeEnvironmentArray(workspace: workspaceName);
                var cts = new CancellationTokenSource();
                var results = Geoprocessing.ExecuteToolAsync("management.AddField",
                    parameters, env, cts.Token, (eventName, o) =>
                        switch (eventName)
                            case "OnValidate":
                                if (((IGPMessage[])o).Any(it => it.Type == GPMessageType.Warning))
                                    var fieldExists = ((IGPMessage[])o).FirstOrDefault(it => it.ErrorCode == 12);
                                    if (fieldExists != null)
                await results;
                return true;
            catch (Exception ex)
                return false;


When calling this method, DeltaLayer points to the second table and env:workspacename computes to the right gdb name (line 11.)

However the fields got added to the first layer!

Am I doing something wrong, or is a bug I cannot control?


Also related:

It is a pain into *** to have same layer names!

The related Add or Deleting-Field Geoprocessing tools have a way to differentiate layers with same names:


However the Content does not use this technique, and neither the Attribute Table(s):

(I still differentiate them by the presence of the db_operation field, but it is the 90th column in the above grid!)