Unable to set GUID fields programmatically (UWP, Win10, VS2017, C#, ArcGIS Runtime SDK .NET 100.0.0)

06-29-2017 09:57 AM
New Contributor

While trying to build a workaround for the lack of related table/feature support in 100.0.0 I found that I'm not able to set any GUID field values. The goal is to set the foreign key value for a feature to the GlobalID value of its related feature in the geodatabase in code. My relationships are all 1-M in the geodatabase.

On the coding side it works just fine until I perform the following:

var saveResults = await table.SaveChangesAsync();

Where table is a ServiceFeatureTable.

In my many iterations, I found that the following do not work:

  • GUID fields cannot be unassigned/null, so I have to put something in there.
  • Setting the value to a valid GlobalID value fails.
  • new Guid() (i.e. no related feature) also fails.

I get an ArcGISWebException error "Unable to complete operation" with the detailed message "Setting of value for DeviceID failed." for all non-null values. Null/unassigned values just fail because GUIDs cannot be null.

I'm using the ArcGIS Server 10.5.0 (build 6491), Windows Server 2012 R2, and SQL Server 2014 on the backend, all with the latest updates.

This is the final piece of the puzzle to complete my project. Any help would be greatly appreciated. 

0 Kudos
7 Replies
Occasional Contributor II

Here is some sample code that works for me in v100. 

feature is an ArcGISFeature.

After this, you can then use FeatureTable.AddFeatureAsync() and ServiceFeatureTable.ApplyEditsAsync() as required.  

Hope this helps.

//Create a new Guid and get the field from the table
 var guid = Guid.NewGuid ();
var guidFld = feature.FeatureTable.Fields.FirstOrDefault (f => f.Name == fieldName.Trim()); 

//Make sure the field is found, editable, and then set the value
if (guidFld != null) {
    if (guidFld.IsEditable)
        feature.SetAttributeValue (fieldName.Trim (), guid); 


0 Kudos
New Contributor

Thanks for the Field.IsEditable. I didn't have that, and it's definitely something that should have been in my code from the start. It unfortunately didn't fix my problem.

After further investigation (after added the Field.IsEditable) I found these 2 rather helpful elements in the feature service logs:

<Msg time='2017-06-29T13:28:23,800' type='SEVERE' code='17000' target='GravelCheckers/GravelAppOnly_GravelCheckers.MapServer' methodName='FSGraphicFeature::PopulateBuffer' machine='GISDMZ' process='8704' thread='904' user='anonymous' >Error: A general error when something is wrong with a Field. [DeviceID].</Msg>

<Msg time='2017-06-29T13:28:23,800' type='SEVERE' code='17000' target='GravelCheckers/GravelAppOnly_GravelCheckers.MapServer' methodName='GraphicFeatureLayer.Add' machine='GISDMZ' process='8704' thread='904' user='anonymous' >Edit for the Feature in Layer: 9 is not applied.</Msg>

Any idea what this means? DeviceID is the foreign key field that I'm trying to populate, and I don't understand the second message either.

0 Kudos
Occasional Contributor II

Haven't ever seen those error messages.

Couple of things:

- Did you try the code using a new guid?

- Can you confirm the field type for DeviceID is an esriFieldTypeGUID?

- Did you publish the services with ArcMap or ArcGIS Pro?  I've seen some posting on different results based on the method the services were published.

- Are you working online or offline, or both?  If only online, do you get the same, or different (possibly more helpful) message when working offline.

That's all that comes to mind right now.

0 Kudos
New Contributor

In order:

  • Guid.NewGuid() yields the same failed results. The same service logs are created as well.
  • field.FieldType = FieldType.Guid
  • ArcMap 10.5, and I have ArcGIS Pro on my development machine but I've never used it. Should I republish the feature service to see if that'll help?
  • Online only. I first wrote the app to work offline using the SDK, but it failed to sync back to the server for a host of other undefinable/unintelligible reasons. I'm storing the data offline using Sqlite and Entity Framework 7, manually converting to and from my models and Features, with a model field that stores the GlobalID of the features used in syncing back to the feature service and for assigning the foreign keys. This method works perfectly for the top level feature classes (the ones that don't have foreign key fields that need to be assigned). I've compared the GUIDs in the geodatabase to the ones that are assigned to foreign keys in the code and they are identical 100% of the time.
0 Kudos
Occasional Contributor II

I've not used Pro, but I have seen this forum that others have been having issues.  Using ArcMap is what I used and I've been able to get that code to work and successfully store a Guid.

So when you are trying to save the GUID, is it directly to the online service, or to a local SQLite database?  

Have you tried to edit one of these features in AGOL or Portal?  Wonder if that would work/fail and/or give you a better message.

0 Kudos
New Contributor

I'm not able to see the DeviceID foreign key field on the table that uses it in AGOL. Setting the value in ArcGIS Pro (the UI is extremely confusing) worked well enough. The data synced down to my test device perfectly.

You've given me a lot to think about. It'll keep working on this and post an update once I get it to work. Thanks 

0 Kudos
Esri Frequent Contributor


The newly released v100.1 API now includes support for working with related tables: Relate features—ArcGIS Runtime SDK for .NET (WPF) | ArcGIS for Developers



0 Kudos