Select to view content in your preferred language

FeatureLayer Update method does not work

2364
6
05-02-2011 11:13 AM
BrianGustafson
Occasional Contributor
When I try and run the update method on all feature layers in the map I get an error that the object in null.  when i debug this is not the case and all of the information looks correct. I am I using this method right?

FeatureLayer f = new FeatureLayer();
foreach (Layer _layer in MyMap.Layers)
{
   if (_layer is FeatureLayer)
   {
       f = _layer as FeatureLayer;
       f.Update();
    }
}
0 Kudos
6 Replies
DominiqueBroux
Esri Frequent Contributor
At first glance, your code looks correct.

We will need more infos about the stack trace and the error message when it happens.
0 Kudos
BrianGustafson
Occasional Contributor
Here is the stacktrace

   at ESRI.ArcGIS.Client.FeatureLayer.update()
   at ESRI.ArcGIS.Client.FeatureLayer.Update()
   at WorkOrderProcessor.MainPage.CloseWOCompleted(Object sender, CloseWOCompletedEventArgs e)
   at WorkOrderProcessor.WOTask.WOTasksClient.OnCloseWOCompleted(Object state)

I attached an image of the error as well.  Also, when I look at the properties of the object while debugging all of the values are correct (i.e. URL)
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Hi Brian,

Thanks for these infos.

Could you also share how the feature layer is created (code, xaml, coming from a web map?) ?

Thanks
0 Kudos
BrianGustafson
Occasional Contributor
I included the code to create one of the layers below.  However, I had an idea.  The application I am creating is a tabbed application.  So if a tab with a map on it is not opened is the layer ever initialized?  I am wondering now if the issue is that the layer is never initialized because that tab was never opened.  Could that be the case?

<esri:FeatureLayer ID="MyTreePts" Url="xxxxxxxx" DisableClientCaching="True" Mode="OnDemand"   
          Where="COMPLETE_DATE IS NULL" Renderer="{StaticResource MyTreePtRenderer}" MouseLeftButtonDown="FeatureLayer_MouseLeftButtonDown">
          <esri:FeatureLayer.Geometry>
           <esri:Envelope XMin="-113" YMin="27" XMax="-97" YMax="48" >
            <esri:Envelope.SpatialReference>
             <esri:SpatialReference WKID="4326"/>
            </esri:Envelope.SpatialReference>
           </esri:Envelope>
          </esri:FeatureLayer.Geometry>
          <esri:FeatureLayer.OutFields>
           <sys:String>OBJECTID</sys:String>
           <sys:String>COMMENTS</sys:String>
           <sys:String>GLOBALID</sys:String>
          </esri:FeatureLayer.OutFields>
          <esri:FeatureLayer.MapTip>
           <Border CornerRadius="10" BorderBrush="#FF222957" BorderThickness="3" Margin="0,0,15,15">
            <Border.Background>
             <LinearGradientBrush EndPoint="1.038,1.136" StartPoint="0.015,0.188">
              <GradientStop Color="#FFD1DFF2"/>
              <GradientStop Color="#FF0088FF" Offset="0.946"/>
             </LinearGradientBrush>
            </Border.Background>
            <Border.Effect>
             <DropShadowEffect ShadowDepth="10" BlurRadius="14" Direction="300" />
            </Border.Effect>
            <StackPanel Margin="7">
             <TextBlock Text="Tree Point Condition" Foreground="Black" />
             <StackPanel Orientation="Horizontal">
              <TextBlock Text="Comments: " Foreground="Black" />
              <TextBlock Text="{Binding ConverterParameter=COMMENTS, Converter={StaticResource MyDictionaryConverter}, Mode=OneWay}" Foreground="Black" />
             </StackPanel>
            </StackPanel>
           </Border>
          </esri:FeatureLayer.MapTip>
         </esri:FeatureLayer>
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I am wondering now if the issue is that the layer is never initialized because that tab was never opened. Could that be the case?


That's a good point.
After some research, I found that this may have been fixed in 2.2. Which version are you using?

With 2.1, the workaround might be to test if(layer.IsInitialized) before calling Update.
0 Kudos
BrianGustafson
Occasional Contributor
The issue was that the layer was never initialized.  When I only run update on initialized layers it works.  I am using version 2.1 of the API so I don't know if this will work with 2.2.

Thanks.
0 Kudos