<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Can not delete feature from Local Server under ArcGIS Runtime 100.12 (feature gets deleted successfully then reappears) in .NET Maps SDK Questions</title>
    <link>https://community.esri.com/t5/net-maps-sdk-questions/can-not-delete-feature-from-local-server-under/m-p/1111548#M10585</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;After upgrading from ArcGIS Runtime 100.9 to 100.12, I can no longer delete features from a ServiceFeatureTable provided using a LocalServer.&lt;/P&gt;&lt;P&gt;More exactly, the code for deleting the feature executes just fine, the number of features in the feature table decreases, but if I zoom in/out, the deleted feature reappears.&lt;/P&gt;&lt;P&gt;I have stitched together a simple test app from the following ArcGIS Runtime Samples:&amp;nbsp;Local Server Services, Feature Layer Selection, Delete Features (feature service)&lt;/P&gt;&lt;P&gt;The result is the same. When I tap a feature it gets deleted and the count decreases from 17 to 16. It stays at 16 while I move the map around, but once I zoom the feature pops back into existence and the feature count is 17.&lt;/P&gt;&lt;P&gt;Note: I have also tried using&amp;nbsp;Esri.ArcGISRuntime.LocalServices version 100.9 in combination with Esri.ArcGISRuntime 100.12 or 100.11, but had the same results.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;using Esri.ArcGISRuntime;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.LocalServices;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.UI.Controls;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp1 {
    /// &amp;lt;summary&amp;gt;
    /// Interaction logic for MainWindow.xaml
    /// &amp;lt;/summary&amp;gt;
    public partial class MainWindow : Window {

        LocalFeatureService _localFeatureService;
        FeatureLayer _featureLayer;

        public MainWindow() {
            InitializeComponent();

            Initialize();
        }

        private async void Initialize() {
            // Create a map and add it to the view
            MyMapView.Map = new Map(Basemap.CreateImagery());

            try {
                // LocalServer must not be running when setting the data path.
                if (LocalServer.Instance.Status == LocalServerStatus.Started) {
                    await LocalServer.Instance.StopAsync();
                }

                // Set the local data path - must be done before starting. On most systems, this will be C:\EsriSamples\AppData.
                // This path should be kept short to avoid Windows path length limitations.
                string tempDataPathRoot = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.Windows)).FullName;
                string tempDataPath = System.IO.Path.Combine(tempDataPathRoot, "EsriSamples", "AppData");
                Directory.CreateDirectory(tempDataPath); // CreateDirectory won't overwrite if it already exists.
                LocalServer.Instance.AppDataPath = tempDataPath;

                // Start the local server instance
                await LocalServer.Instance.StartAsync();
            } catch (Exception ex) {
                var localServerTypeInfo = typeof(LocalMapService).GetTypeInfo();
                var localServerVersion = FileVersionInfo.GetVersionInfo(localServerTypeInfo.Assembly.Location);

                MessageBox.Show($"Please ensure that local server {localServerVersion.FileVersion} is installed prior to using the sample. The download link is in the description. Message: {ex.Message}", "Local Server failed to start");
                return;
            }

            // Load the sample data and get the path
            string myfeatureServicePath = GetFeatureLayerPath();

            // Create the feature service to serve the local data
            _localFeatureService = new LocalFeatureService(myfeatureServicePath);

            // Listen to feature service status changes
            _localFeatureService.StatusChanged += _localFeatureService_StatusChanged;

            // Start the feature service
            try {
                await _localFeatureService.StartAsync();
            } catch (Exception ex) {
                MessageBox.Show(ex.Message, "The feature service failed to load");
            }
        }

        private async void _localFeatureService_StatusChanged(object sender, StatusChangedEventArgs e) {
            // Load the map from the service once ready
            if (e.Status == LocalServerStatus.Started) {
                // Get the path to the first layer - the local feature service url + layer ID
                string layerUrl = _localFeatureService.Url + "/0";

                // Create the ServiceFeatureTable
                ServiceFeatureTable myFeatureTable = new ServiceFeatureTable(new Uri(layerUrl));

                // Create the Feature Layer from the table
                _featureLayer = new FeatureLayer(myFeatureTable);

                // Add the layer to the map
                MyMapView.Map.OperationalLayers.Add(_featureLayer);

                try {
                    // Wait for the layer to load
                    await _featureLayer.LoadAsync();

                    // Set the viewpoint on the MapView to show the layer data
                    await MyMapView.SetViewpointGeometryAsync(_featureLayer.FullExtent, 50);

                    MyMapView.GeoViewTapped += OnMapViewTapped;
                } catch (Exception ex) {
                    MessageBox.Show(ex.ToString(), "Error");
                }
            }
        }

        private async void OnMapViewTapped(object sender, GeoViewInputEventArgs e) {
            try {
                // Define the selection tolerance.
                double tolerance = 15;

                // Convert the tolerance to map units.
                double mapTolerance = tolerance * MyMapView.UnitsPerPixel;

                // Get the tapped point.
                MapPoint geometry = e.Location;

                // Normalize the geometry if wrap-around is enabled.
                //    This is necessary because of how wrapped-around map coordinates are handled by Runtime.
                //    Without this step, querying may fail because wrapped-around coordinates are out of bounds.
                if (MyMapView.IsWrapAroundEnabled) {
                    geometry = (MapPoint)GeometryEngine.NormalizeCentralMeridian(geometry);
                }

                // Define the envelope around the tap location for selecting features.
                Envelope selectionEnvelope = new Envelope(geometry.X - mapTolerance, geometry.Y - mapTolerance, geometry.X + mapTolerance,
                    geometry.Y + mapTolerance, MyMapView.Map.SpatialReference);

                // Define the query parameters for selecting features.
                QueryParameters queryParams = new QueryParameters
                {
                    // Set the geometry to selection envelope for selection by geometry.
                    Geometry = selectionEnvelope
                };

                // Select the features based on query parameters defined above.
                ServiceFeatureTable table = (ServiceFeatureTable)_featureLayer.FeatureTable;
                long featureCountOld = table.NumberOfFeatures;
                bool deletedStuff = false;
                var results = await _featureLayer.SelectFeaturesAsync(queryParams, Esri.ArcGISRuntime.Mapping.SelectionMode.New);
                foreach (var feature in results) {
                    // delete feature from feature table
                    await table.DeleteFeatureAsync(feature);
                    // Sync the change with the service.
                    await table.ApplyEditsAsync();

                    deletedStuff = true;
                }
                long featureCountNew = table.NumberOfFeatures;

                if (deletedStuff) {
                    MessageBox.Show($"Deleted features, feature count changed from {featureCountOld} to {featureCountNew}");
                } else {
                    MessageBox.Show($"Nothing deleted, feature count is {featureCountOld}");
                }
                
            } catch (Exception ex) {
                MessageBox.Show(ex.ToString(), "Error");
            }
        }

        private static string GetFeatureLayerPath() {
            return @"D:\PointsofInterest.mpkx";
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Oct 2021 08:58:35 GMT</pubDate>
    <dc:creator>Andrei</dc:creator>
    <dc:date>2021-10-27T08:58:35Z</dc:date>
    <item>
      <title>Can not delete feature from Local Server under ArcGIS Runtime 100.12 (feature gets deleted successfully then reappears)</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/can-not-delete-feature-from-local-server-under/m-p/1111548#M10585</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;After upgrading from ArcGIS Runtime 100.9 to 100.12, I can no longer delete features from a ServiceFeatureTable provided using a LocalServer.&lt;/P&gt;&lt;P&gt;More exactly, the code for deleting the feature executes just fine, the number of features in the feature table decreases, but if I zoom in/out, the deleted feature reappears.&lt;/P&gt;&lt;P&gt;I have stitched together a simple test app from the following ArcGIS Runtime Samples:&amp;nbsp;Local Server Services, Feature Layer Selection, Delete Features (feature service)&lt;/P&gt;&lt;P&gt;The result is the same. When I tap a feature it gets deleted and the count decreases from 17 to 16. It stays at 16 while I move the map around, but once I zoom the feature pops back into existence and the feature count is 17.&lt;/P&gt;&lt;P&gt;Note: I have also tried using&amp;nbsp;Esri.ArcGISRuntime.LocalServices version 100.9 in combination with Esri.ArcGISRuntime 100.12 or 100.11, but had the same results.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;using Esri.ArcGISRuntime;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.LocalServices;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.UI.Controls;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp1 {
    /// &amp;lt;summary&amp;gt;
    /// Interaction logic for MainWindow.xaml
    /// &amp;lt;/summary&amp;gt;
    public partial class MainWindow : Window {

        LocalFeatureService _localFeatureService;
        FeatureLayer _featureLayer;

        public MainWindow() {
            InitializeComponent();

            Initialize();
        }

        private async void Initialize() {
            // Create a map and add it to the view
            MyMapView.Map = new Map(Basemap.CreateImagery());

            try {
                // LocalServer must not be running when setting the data path.
                if (LocalServer.Instance.Status == LocalServerStatus.Started) {
                    await LocalServer.Instance.StopAsync();
                }

                // Set the local data path - must be done before starting. On most systems, this will be C:\EsriSamples\AppData.
                // This path should be kept short to avoid Windows path length limitations.
                string tempDataPathRoot = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.Windows)).FullName;
                string tempDataPath = System.IO.Path.Combine(tempDataPathRoot, "EsriSamples", "AppData");
                Directory.CreateDirectory(tempDataPath); // CreateDirectory won't overwrite if it already exists.
                LocalServer.Instance.AppDataPath = tempDataPath;

                // Start the local server instance
                await LocalServer.Instance.StartAsync();
            } catch (Exception ex) {
                var localServerTypeInfo = typeof(LocalMapService).GetTypeInfo();
                var localServerVersion = FileVersionInfo.GetVersionInfo(localServerTypeInfo.Assembly.Location);

                MessageBox.Show($"Please ensure that local server {localServerVersion.FileVersion} is installed prior to using the sample. The download link is in the description. Message: {ex.Message}", "Local Server failed to start");
                return;
            }

            // Load the sample data and get the path
            string myfeatureServicePath = GetFeatureLayerPath();

            // Create the feature service to serve the local data
            _localFeatureService = new LocalFeatureService(myfeatureServicePath);

            // Listen to feature service status changes
            _localFeatureService.StatusChanged += _localFeatureService_StatusChanged;

            // Start the feature service
            try {
                await _localFeatureService.StartAsync();
            } catch (Exception ex) {
                MessageBox.Show(ex.Message, "The feature service failed to load");
            }
        }

        private async void _localFeatureService_StatusChanged(object sender, StatusChangedEventArgs e) {
            // Load the map from the service once ready
            if (e.Status == LocalServerStatus.Started) {
                // Get the path to the first layer - the local feature service url + layer ID
                string layerUrl = _localFeatureService.Url + "/0";

                // Create the ServiceFeatureTable
                ServiceFeatureTable myFeatureTable = new ServiceFeatureTable(new Uri(layerUrl));

                // Create the Feature Layer from the table
                _featureLayer = new FeatureLayer(myFeatureTable);

                // Add the layer to the map
                MyMapView.Map.OperationalLayers.Add(_featureLayer);

                try {
                    // Wait for the layer to load
                    await _featureLayer.LoadAsync();

                    // Set the viewpoint on the MapView to show the layer data
                    await MyMapView.SetViewpointGeometryAsync(_featureLayer.FullExtent, 50);

                    MyMapView.GeoViewTapped += OnMapViewTapped;
                } catch (Exception ex) {
                    MessageBox.Show(ex.ToString(), "Error");
                }
            }
        }

        private async void OnMapViewTapped(object sender, GeoViewInputEventArgs e) {
            try {
                // Define the selection tolerance.
                double tolerance = 15;

                // Convert the tolerance to map units.
                double mapTolerance = tolerance * MyMapView.UnitsPerPixel;

                // Get the tapped point.
                MapPoint geometry = e.Location;

                // Normalize the geometry if wrap-around is enabled.
                //    This is necessary because of how wrapped-around map coordinates are handled by Runtime.
                //    Without this step, querying may fail because wrapped-around coordinates are out of bounds.
                if (MyMapView.IsWrapAroundEnabled) {
                    geometry = (MapPoint)GeometryEngine.NormalizeCentralMeridian(geometry);
                }

                // Define the envelope around the tap location for selecting features.
                Envelope selectionEnvelope = new Envelope(geometry.X - mapTolerance, geometry.Y - mapTolerance, geometry.X + mapTolerance,
                    geometry.Y + mapTolerance, MyMapView.Map.SpatialReference);

                // Define the query parameters for selecting features.
                QueryParameters queryParams = new QueryParameters
                {
                    // Set the geometry to selection envelope for selection by geometry.
                    Geometry = selectionEnvelope
                };

                // Select the features based on query parameters defined above.
                ServiceFeatureTable table = (ServiceFeatureTable)_featureLayer.FeatureTable;
                long featureCountOld = table.NumberOfFeatures;
                bool deletedStuff = false;
                var results = await _featureLayer.SelectFeaturesAsync(queryParams, Esri.ArcGISRuntime.Mapping.SelectionMode.New);
                foreach (var feature in results) {
                    // delete feature from feature table
                    await table.DeleteFeatureAsync(feature);
                    // Sync the change with the service.
                    await table.ApplyEditsAsync();

                    deletedStuff = true;
                }
                long featureCountNew = table.NumberOfFeatures;

                if (deletedStuff) {
                    MessageBox.Show($"Deleted features, feature count changed from {featureCountOld} to {featureCountNew}");
                } else {
                    MessageBox.Show($"Nothing deleted, feature count is {featureCountOld}");
                }
                
            } catch (Exception ex) {
                MessageBox.Show(ex.ToString(), "Error");
            }
        }

        private static string GetFeatureLayerPath() {
            return @"D:\PointsofInterest.mpkx";
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Oct 2021 08:58:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/can-not-delete-feature-from-local-server-under/m-p/1111548#M10585</guid>
      <dc:creator>Andrei</dc:creator>
      <dc:date>2021-10-27T08:58:35Z</dc:date>
    </item>
  </channel>
</rss>

