and on button click it is like private void button2_Click(object sender, RoutedEventArgs e) { FeatureLayer featureLayer = MyMap.Layers["polygonlayer"] as FeatureLayer; Graphic gpoly = new Graphic(); gpoly = featureLayer.Graphics.FirstOrDefault(gtt => (int)gtt.Attributes["LOCATION_ID"] == 395); }
the polygon with 395 is available in map layer but here i am getting error object reference not set to an instance of object.
the above code is working fine for point layer as well it is working if i create feature service.but here i want to use map service.you can see from url my services are on and also if you query on 395 location_id that feature is
since Attribute["LOCATION_ID"] can be null, it cannot cast to int. Also if the Key is not DisplayField, you need to include it in your FeatureLayer.OutFields.