Select to view content in your preferred language

Newbie Question

1229
9
12-15-2011 09:15 AM
BlairOrr
Emerging Contributor
I am a student in the GIS program here in Salmon Arm, Canada. I am trying to replicate the Network Analyst Route Sample in my map project. I've created an arcmap with a network dataset and published with ArcGIS Server.

I've copied and pasted the .xaml code from the example into notepad, changed the url to my map location and pasted that below what I've been calling the "Map Load" sequence. The error: multiple root elements comes up when I run.

I've tried to nest the
<UserControl x:Class="ArcGISSilverlightSDK.Routing" sequence from the example within the
<UserControl x:Class="ModIIISilverlight.MainPage" sequence but the error list then tells me the <UserControl x:Class="ArcGISSilverlightSDK.Routing" must be a root element.

Could you please give me a little direction?
Thank you in advance,
Blair
0 Kudos
9 Replies
JenniferNery
Esri Regular Contributor
When you create a new Silverlight Application, you will get something like this. Only overwrite the highlighted text in red. You don't want to replace x:Class, xmlns, xmlns:x. Copy from xmlns:esri instead.

<UserControl x:Class="SilverlightApplication1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">

    </Grid>
</UserControl>
0 Kudos
BlairOrr
Emerging Contributor
Holy Cow! Thank you very much for such a quick response! I followed your advice as well as copied and pasted the "code behind VB" into my MainPage.xaml.vb page.

This process left me with a wack of error messages which I have largely sorted out.

I am now down to 3 errors like:

Error: Reference to a non-shared member requires an object reference. D:\inetpub\wwwroot\ModIIISilverlight\ModIIISilverlight\MainPage.xaml.vb 15 38 ModIIISilverlight
which relate to lines like:
             stopsGraphicsLayer = TryCast(Map.Layers("MyStopsGraphicsLayer"), GraphicsLayer)

and 1 error:


Error:    Could not load file or assembly 'System.Runtime.Serialization, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified. D:\inetpub\wwwroot\ModIIISilverlight\ModIIISilverlight\MainPage.xaml 1 1 ModIIISilverlight

These 2 error types have me stymied. Would you be able to respond with a suggestion or two and also a bit of an explanation? This is a massive learning experience for me.

Best Regards,
Blair
0 Kudos
BlairOrr
Emerging Contributor
So, I sorted out the:

Error: Could not load file or assembly 'System.Runtime.Serialization, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified. D:\inetpub\wwwroot\ModIIISilverlight\ModIIISilverlight\MainPage.xaml 1 1 ModIIISilverlight

and am now just left with the 3:

Error: Reference to a non-shared member requires an object reference. D:\inetpub\wwwroot\ModIIISilverlight\ModIIISilverlight\MainPage.xaml.vb 15 38 ModIIISilverlight

Could it be they, too require a reference be added? If so, each error is specifically related to:

MyRouteGraphicsLayer
MyRouteTask
Map.SpatialReference

Respectively. Are you able to point me in the correct direction for them?
0 Kudos
BlairOrr
Emerging Contributor
Hey!

Below are two of the lines of code which are generating the errors noted in the prior message.

stopsGraphicsLayer = TryCast(Map.Layers("MyStopsGraphicsLayer"), GraphicsLayer)
routeGraphicsLayer = TryCast(Map.Layers("MyRouteGraphicsLayer"), GraphicsLayer)

The error appears to generated concerning the Map.Layers portion as intellisense does not recognize it. Rather, it generates a Map.LayersProperties object.

Any thoughts as to why?

Blair
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Likely the error is coming from the way you defined the layers.

Did you look at the interactive samples?, there are lot of samples (even in VB) that should be useful to begin with.
0 Kudos
MichaelKohler
Frequent Contributor
Perhaps it is the Map.Layers portion causing the error.

What is the name of your Map in xaml is it "Map"?

<esri:Map x:Name="MyMap" .......


Then the call would be like:
stopsGraphicsLayer = TryCast(MyMap.Layers("MyStopsGraphicsLayer"), GraphicsLayer)
0 Kudos
JenniferNery
Esri Regular Contributor
Kindly check that your project references ESRI.ArcGIS.Client. I assume you were able to get rid of System.Runtime.Serialization error, by adding this reference.

Also when copying code-behind, you need not replace your namespace, class name and constructor. You just copy the using or imports statements and code after InitializeComponent.
0 Kudos
BlairOrr
Emerging Contributor
Thank you all for your responses. I have referenced ESRI.ArcGIS.Client yet continue to have the System.Runtime.Serialization error refering to line 1, Column 1. I obviously do not understand how to write the "x:Class="__________" correctly. If I am understanding what I am looking at, is this not the line which refers this silverlight main page to my ArcGIS Server published map?
Blair
0 Kudos
JenniferNery
Esri Regular Contributor
0 Kudos