Select to view content in your preferred language

Change FeatureLayer.DefinitionExpression and Catch a Exception

1355
5
06-15-2017 11:49 PM
xiaoguangyan
Emerging Contributor

Recently I change the FeatureLayer.DefinitionExpression(set FeatureLayer.DefinitionExpression="*****" then FeatureLayer.DefinitionExpression="") it will catch a exception with message "write protected memory. This usually indicates that other memory has been damaged" showed.

0 Kudos
5 Replies
JenniferNery
Esri Regular Contributor

What version of the API are you using? I'm not able to reproduce with released version v100 with the following code.

To use, hit "Enter" key to execute update on FeatureLayer.DefinitionExpression, should only display states that begin with 'N'

Clearing the text and hit "Enter" again, should display all states.

I'm able to update the definition expression without issue.


Can you share some repro code or try code below to see if you can get the an exception? Thanks.

        xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">
    <Grid>
        <esri:MapView x:Name="MyMapView" />
        <StackPanel VerticalAlignment="Top"
                    HorizontalAlignment="Right">
            <TextBox Text="STATE_NAME LIKE 'N%'"
                     Width="250"
                     KeyUp="OnKeyUp"/>            
        </StackPanel>
    </Grid>
        public MainWindow()
        {
            InitializeComponent();
            MyMapView.Map = new Map(Basemap.CreateTopographic());
            MyMapView.Map.OperationalLayers.Add(new FeatureLayer(new Uri("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3")));
        }

        private void OnKeyUp(object sender, KeyEventArgs e)
        {
            if(e.Key == Key.Enter)
            {
                var clause = ((TextBox)sender).Text.Trim();
                var layer = (FeatureLayer)MyMapView.Map.OperationalLayers[0];
                layer.DefinitionExpression = clause;
            }
        }
0 Kudos
xiaoguangyan
Emerging Contributor

Hi Jennifer

I noticed that when I set the property FeatureLayer.LabelsEnabled then update the definition expression will catch a exception, remove property FeatureLayer.LabelsEnabled codes go well, is the LabelsEnabled matters in update the definition expression

0 Kudos
xiaoguangyan
Emerging Contributor

Are properties FeatureLayer.LabelsEnabled and FeatureLayer.DefinitionExpression conflicted?

0 Kudos
JenniferNery
Esri Regular Contributor

Thank you, Xiaoguang for reporting this bug.

I'm able to repro the issue that AccessViolationException is thrown when DefinitionExpression is cleared when LabelsEnabled is true in v100.

Fortunately, this is no longer reproducible in Update 1. However when using v100, to workaround this bug meanwhile, you can mark LabelsEnabled false if the new DefinitionExpression will be empty and set it back to true.

if (string.IsNullOrEmpty(clause) && isLabelsEnabled)
    layer.LabelsEnabled = false;
layer.DefinitionExpression = clause;
if(string.IsNullOrEmpty(clause)&& isLabelsEnabled)
    layer.LabelsEnabled = true;
0 Kudos
xiaoguangyan
Emerging Contributor

Thank you for the same and for my question

0 Kudos