Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I m using the following c# code to add my layer dynamically on a 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 m I wrong?

Thanks in advance!

share|improve this question
up vote 2 down vote accepted

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...
share|improve this answer
I use mylayer_Initialized only for populating some comboboxes... How can I add to get spatia reference? – voimak Jun 14 '13 at 9:34
it works! thanks!!! – voimak Jun 14 '13 at 10:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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