I'm using the following C# code to add my layer dynamically on an ArcGIS silverlight application:

ArcGISDynamicMapServiceLayer mylayer = new ArcGISDynamicMapServiceLayer()
   ID = layerName,
   Url = mapServiceUrl,
 mylayer.Initialized += mylayer _Initialized;
 mylayer.InitializationFailed += mylayer _Failed;
 myMap.Layers.Add(mylayer );

But when I try to get the spatial reference of the layer using:

SpatialReference sp = mylayer.SpatialReference;
int testww = sp.WKID;

I get an error "Object reference not set to an instance of an object." because mylayer.SpatialReference is Null.

Where am I going wrong?


To get the spatial reference of the layer ,Initialized event is useful, i.e. your "mylayer _Initialized" event.Have you tried that?

private void MyService_Initialized(object sender, EventArgs e)
Layer layer = sender as Layer;

//get spatial reference here...
  • I use mylayer_Initialized only for populating some comboboxes... How can I add to get spatia reference? – voimak Jun 14 '13 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.