Select to view content in your preferred language

API 2.0 Feature Layer errors

804
4
08-03-2010 05:51 AM
StephenSporik
Deactivated User
Hello,

I am upgrading an web application from the v1.2 API to v2.0.
In addition we have moved to Silverlight 4, .Net 4.0, and Visual Studio 2010.

After having completed the reference updates and other necesarry improvements to our development environment, I am left with one nagging problem.  The feature Layers will not instantiate.  They are declared in XAML and I set the symbols in the code behind as well as set the outfields. 

I receive an error at runtime that the feature layer is not set to an instance of an object.

I have created an Initialization Failed event listener and the error message is simply:

"Server Error - Object not set to an instance of an object."

I have one dynamic service map layer and four feature layers.
The dynamic service layer displays fine, as does the FIRST feature layer.  But the other three are not displaying, throwing this error.  I have checked my map services, and checked the end points through rest.  I have even recreated the services in ArcGIS Server 10 and have the same problem.

I've also noticed that you cannot change the URL of a FeatureLayer at runtime?  Is this correct?

Below is my XAML, you can see I set maptips and outfields for the first layer to use native maptips.  For the other layers I have custom maptips that I set in code behind.


 <esri:Map x:Name="FloorplanSpatial"
                          Extent="1354190, 556290, 1354335, 556410"
                          Width="495"
                          Height="490"
                          IsLogoVisible="False">
         <esri:Map.Layers>

             <esri:ArcGISDynamicMapServiceLayer  ID="ElectricFeatures"
                                                            Url="http://myserver.com/ArcGIS/rest/services/ServiceName/MapServer/"
                                                            DisableClientCaching="True"
                                                            ImageFormat="JPG" />

              <esri:FeatureLayer ID="BreakerBoxControls"
                                           MouseLeftButtonDown="BreakerBoxControls_MouseLeftButtonDown"
                                           Url="http://http://myserver.com/ArcGIS/rest/services/ServiceName/MapServer//1">

                            <esri:FeatureLayer.OutFields>
                                <sys:String>PANELNAME</sys:String>
                            </esri:FeatureLayer.OutFields>
                            <esri:FeatureLayer.MapTip>

                                <Grid Margin="0,15,15,0">
                                    <Rectangle RadiusX="5"
                                               RadiusY="5"
                                               Fill="LightGray"
                                               Margin="0,4,0,0" />
                                    <Rectangle Stroke="Gray"
                                               RadiusX="5"
                                               RadiusY="5"
                                               Fill="#775C90B2"
                                               Margin="0,0,0,5" />
                                    <Rectangle Fill="#FFFFFFFF"
                                               Stroke="DarkGray"
                                               RadiusX="5"
                                               RadiusY="5"
                                               Margin="10,10,10,15" />
                                    <StackPanel Margin="5,5,5,5"
                                                Background="White">

                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="Panel:  "
                                                       Margin="3,0,3,0" />
                                            <TextBlock Text="{Binding [PANELNAME]}"
                                                       FontWeight="Bold" />
                                        </StackPanel>

                                    </StackPanel>
                                </Grid>
                            </esri:FeatureLayer.MapTip>
                        </esri:FeatureLayer>
                                           

                        <esri:FeatureLayer ID="HVACcontrols"
                                           Url="http://myserver.com/ArcGIS/rest/services/ServiceName/MapServer/6"
                                           Visible="True" InitializationFailed="FeatureLayer_InitializationFailed">
                        </esri:FeatureLayer>

                        <esri:FeatureLayer ID="HVAC_VAVboxes"                                           Url="http://myserver.com/ArcGIS/rest/services/ServiceName/MapServer/7"
                                           Visible="True" InitializationFailed="FeatureLayer_InitializationFailed">
                        </esri:FeatureLayer>
                        
                        <esri:FeatureLayer ID="HVAC_RTU"
                                           Url="http://myserver.com/ArcGIS/rest/services/ServiceName/MapServer/26"
                                           Visible="False" InitializationFailed="FeatureLayer_InitializationFailed">
                        </esri:FeatureLayer>
                        
                    </esri:Map.Layers>
                </esri:Map>


Here is my code behind.  It fails at the .Update() function.  If I comment that out, I still get an Unhandled Silverlight error.

Dim dynamicServiceLayer As ArcGISDynamicMapServiceLayer = TryCast(FloorplanSpatial.Layers("ElectricFeatures"), ArcGISDynamicMapServiceLayer)
        dynamicServiceLayer.VisibleLayers = HVACTabFloor2Collection

        Dim HVACcontrolsLayer As FeatureLayer = TryCast(FloorplanSpatial.Layers("HVACcontrols"), FeatureLayer)
        Dim HVACcontrolsSymbol As SimpleMarkerSymbol = New SimpleMarkerSymbol

        HVACcontrolsSymbol.Color = New SolidColorBrush(Color.FromArgb(20, 0, 0, 0))
        HVACcontrolsSymbol.Style = SimpleMarkerSymbol.SimpleMarkerStyle.Circle
        HVACcontrolsSymbol.Size = 8
        HVACcontrolsLayer.FeatureSymbol = HVACcontrolsSymbol
        HVACcontrolsLayer.Url = "http://myserver.com/ArcGIS/rest/services/ServiceName/MapServer/6"
        HVACcontrolsLayer.Update()
        HVACcontrolsLayer.OutFields.Add("THERMNAME")
        HVACcontrolsLayer.OutFields.Add("USERDOC")
        HVACcontrolsLayer.OutFields.Add("DWG")

        'HVACcontrolsMapTip.GraphicsLayer = HVACcontrolsLayer

        Dim HVACVAVboxesLayer As FeatureLayer = TryCast(FloorplanSpatial.Layers("HVAC_VAVboxes"), FeatureLayer)
        Dim HVACVAVboxesSymbol As SimpleMarkerSymbol = New SimpleMarkerSymbol

        HVACVAVboxesSymbol.Color = New SolidColorBrush(Color.FromArgb(20, 0, 0, 0))
        HVACVAVboxesSymbol.Style = SimpleMarkerSymbol.SimpleMarkerStyle.Square
        HVACVAVboxesSymbol.Size = 10
        HVACVAVboxesLayer.FeatureSymbol = HVACVAVboxesSymbol
        'HVACVAVboxesLayer.Url = "http://myserver.com/ArcGIS/rest/services/ServiceName/MapServer/7"
        'HVACVAVboxesLayer.Update()
        HVACVAVboxesLayer.OutFields.Add("NAME")
        HVACVAVboxesLayer.OutFields.Add("USERDOC")
        HVACVAVboxesLayer.OutFields.Add("DWG")

        'VAVboxesMapTip.GraphicsLayer = HVACVAVboxesLayer

        Dim HVACRTUlayer As FeatureLayer = TryCast(FloorplanSpatial.Layers("HVAC_RTU"), FeatureLayer)
        Dim HVACRTUsymbol As SimpleMarkerSymbol = New SimpleMarkerSymbol

        HVACRTUsymbol.Color = New SolidColorBrush(Color.FromArgb(255, 0, 0, 255))
        HVACRTUsymbol.Style = SimpleMarkerSymbol.SimpleMarkerStyle.Square
        HVACRTUsymbol.Size = 15
        HVACRTUlayer.FeatureSymbol = HVACRTUsymbol
        'HVACRTUlayer.Url = "http://myserver.com/ArcGIS/rest/services/ServiceName/MapServer/26"
        'HVACRTUlayer.Update()
        HVACRTUlayer.OutFields.Add("NAME")
        HVACRTUlayer.OutFields.Add("USERDOC")

        'RTUMapTip.GraphicsLayer = HVACRTUlayer

        Dim CircuitPanelLayer As FeatureLayer = TryCast(FloorplanSpatial.Layers("BreakerBoxControls"), FeatureLayer)
        Dim circuitPanelSymbol As New SimpleMarkerSymbol

        circuitPanelSymbol.Color = New SolidColorBrush(Color.FromArgb(10, 0, 0, 0))
        circuitPanelSymbol.Style = SimpleMarkerSymbol.SimpleMarkerStyle.Circle
        circuitPanelSymbol.Size = 10
        CircuitPanelLayer.FeatureSymbol = circuitPanelSymbol



Any suggestions are appreciated.  Thanks.
0 Kudos
4 Replies
DarinaTchountcheva
Frequent Contributor
Hi Stephen,

Have you resolved your problems?

I am getting the same errors trying to upgrade an application from 1.2 to 2.0.

I cannot set the Url of a FeatureLayer after it has been initialized, so I create the layer in code behind. But then I get an "Object not set to an instance" error on the line where I call the Update method:
fLayer.Update()

And fLayer is not null, but a valid FeatureLayer object.

Any thoughts and ideas are greatly appreciated.
0 Kudos
DarinaTchountcheva
Frequent Contributor
OK, I spoke too soon!

I had to move the code that was calling the Update method to the FeatureLayer Initialized event, because now that was creating it in code, it was not initialized at the moment when I was calling the method before.

Problem resolved, but I don't know why the new version wouldn't allow FeatureLayer's Url to be set after it has been initialized.

I personally use configuration files to set all of the services' URLs, so I don't have to rebuild and redeploy every time I change a service Url.
0 Kudos
dotMorten_esri
Esri Notable Contributor
"I had to move the code that was calling the Update method to the FeatureLayer Initialized event"
In that case there is no need to call update. Update will automatically be called after the layer initialized.
0 Kudos
DarinaTchountcheva
Frequent Contributor
Hi Morten,

Thank  your for your suggestion.
If I don't call Update() it ignores my Where clause and loads all the features on the map, and that is not what I want.

It is working for now, and I have just fixed all of the other breaking errors from the conversion.  I will break it another time for more testing.

😉
0 Kudos