Can't create features on newly created feature class layers

546
3
Jump to solution
12-04-2017 04:50 AM
Highlighted
New Contributor II

Hi,

I'm currently dealing with a strange error message: I'm creating a new feature class (via CreateFeatureclass_management) and adding fields (via AddField_management/AddFields_management) in C# with the Geoprocessing class and that works fine. But after creating the layers and adding the fields I'd also like to create features on these layers.. so I switch to the "Edit" ribbon and click on "Create". I click the vertices of my polyline (or whatever geometry) and when I hit F2 to finish the process, an error message appears in the "Create Features" pane: "Failed to create new feature(s). This data is currently locked by another user and cannot be saved".

But the weird thing is: There's no error message when calling these management-functions via arcpy. I think it's related to adding the fields to the layer since commenting out these calls in my code also results in no error message.. but I need to add fields to new and existing feature layers so leaving this out is not an option for me.

I attached a sample to reproduce the behaviour. The class "Layer" servers as a lightweight wrapper for feature layers and the management-functions are called in Layer.AddToMapAsync and Layer.SetupFieldsAsync.

ArcGIS Pro is version 2.0.1 and the SDK is 2.0.0.8933.

Thanks in advance for any help!

Best Regards

Christian

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Esri Contributor

I see.

So the code works with subsequent feature creation as is in the upcoming 2.1 Pro release.

For the 2.0 there seems to be an issue with creating the fields on the background thread. 

In the SetupFieldsAsync function please remove the QueuedTask portion such that the field creation section reads like the following:

foreach (var field in this.Fields)
{
    var arguments = new List<string>();
    arguments.Add(this.Name);
    arguments.Add(field.Name);
    arguments.Add(field.DataType);
    arguments.Add("");  //Precision
    arguments.Add("");  //Scale
    arguments.Add("");  //Length
    arguments.Add("");  //Alias
    arguments.Add("NULLABLE");

    var result = await ArcGIS.Desktop.Core.Geoprocessing.Geoprocessing.ExecuteToolAsync("AddField_management", arguments.ToArray());
    if (result.ErrorCode != 0)
        throw new Exception("Failed to add field: " + field);
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

and the feature creation does succeed. 

View solution in original post

3 Replies
Highlighted
Esri Contributor

Unfortunately, I was not able to reproduce the error. Your provided sample code works as expected.

Reply
0 Kudos
Highlighted
New Contributor II

Thanks for your reply! The code works for me, too. But what doesn't work is manually creating a feature on the newly created layers afterwards. Did you test that as well? In any case, I'm currently on vacation and maybe the problem lies in my project file which I will upload as soon as I'll be back after the holiday season in January.

Best Regards

Christian

Reply
0 Kudos
Highlighted
Esri Contributor

I see.

So the code works with subsequent feature creation as is in the upcoming 2.1 Pro release.

For the 2.0 there seems to be an issue with creating the fields on the background thread. 

In the SetupFieldsAsync function please remove the QueuedTask portion such that the field creation section reads like the following:

foreach (var field in this.Fields)
{
    var arguments = new List<string>();
    arguments.Add(this.Name);
    arguments.Add(field.Name);
    arguments.Add(field.DataType);
    arguments.Add("");  //Precision
    arguments.Add("");  //Scale
    arguments.Add("");  //Length
    arguments.Add("");  //Alias
    arguments.Add("NULLABLE");

    var result = await ArcGIS.Desktop.Core.Geoprocessing.Geoprocessing.ExecuteToolAsync("AddField_management", arguments.ToArray());
    if (result.ErrorCode != 0)
        throw new Exception("Failed to add field: " + field);
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

and the feature creation does succeed. 

View solution in original post