ServiceFeatureTable not properly initialized

4373
1
Jump to solution
11-10-2015 07:34 AM
AndriusB
New Contributor II

We're noticing strange initialization behavior of ServiceFeatureTable when layer is not added to map and Map is not added to MapView.

We cannot query ServiceFeatureTable and cannot add new features.

ArcGIS Runtime version: 10.2.6.0

//create layer and initialize

var layer = new FeatureLayer(uri);

await layer.InitializeAsync();

//try query table

var table = layer.FeatureTable as ServiceFeatureTable;

var result = await table.QueryAsync(filter);

//last line fails with exception that table is not initialized, even though table.isInitialized == true

//try create new feature

var feature= table.CreateNew();

//last line fails with null reference exception. In debug mode we see clearly that Schema and some other properties are missing even though table.isInitialized == true

Everything works if we add this layer to a Map and MapView in UI (at runtime adding the layer only to Map which is not visible in UI does not solve the problem) and wait for MapView.LayersLoadedAsync().

So the question is, how should we propely initialize ServiceFeatureTable without adding layer to the UI? What does FeatureLayer.InitializeAsync() do if we still have to wait for MapView.LayersLoadedAsync()?

Is it a bug or expected behavior?

I think the question is related to this one, but the answer that was marked as correct seems not to be correct in our case (when feature table is used without MapView)

Re: Proper Way to Edit Service Feature Table Without Map

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

I typically use ServiceFeatureTable.OpenAsync(...).  Here is an quick snippet that I might use.  I also initialize the out fields because you don't get them by default.

// Initialize

var _sft = await ServiceFeatureTable.OpenAsync(fl);

if (_sft.OutFields == null)

{

    _sft.OutFields = new Esri.ArcGISRuntime.Tasks.Query.OutFields();

}

foreach (FieldInfo fi in _sft.Schema.Fields)

{

    _sft.OutFields.Add(fi.Name);

}

//

// Do adds/updates/deletes

//

// Send changes to service

_sft.ApplyEditsAsync();

Hope that helps.

View solution in original post

0 Kudos
1 Reply
by Anonymous User
Not applicable

I typically use ServiceFeatureTable.OpenAsync(...).  Here is an quick snippet that I might use.  I also initialize the out fields because you don't get them by default.

// Initialize

var _sft = await ServiceFeatureTable.OpenAsync(fl);

if (_sft.OutFields == null)

{

    _sft.OutFields = new Esri.ArcGISRuntime.Tasks.Query.OutFields();

}

foreach (FieldInfo fi in _sft.Schema.Fields)

{

    _sft.OutFields.Add(fi.Name);

}

//

// Do adds/updates/deletes

//

// Send changes to service

_sft.ApplyEditsAsync();

Hope that helps.

0 Kudos