IMapServerObjects.get_Map says object is null reference.

المشرف العام

Administrator
طاقم الإدارة
So I am trying to access a map layer, which I can connect to.

try { agsconn.Connect(); Log.Write("Connected.", "myclass"); if (agsconn.IsConnected) { ESRI.ArcGIS.Server.IServerObjectManager som = agsconn.ServerObjectManager; IServerContext serverContext = som.CreateServerContext(mapDocName, "MapServer"); IMapServer mapServer = serverContext.ServerObject as IMapServer; Log.Write("Server context established MapName=" + mapServer.DefaultMapName, "myclass"); ESRI.ArcGIS.Carto.IMapServerObjects mapSO = mapServer as ESRI.ArcGIS.Carto.IMapServerObjects; Log.Write("IMapServerObjects created", "myclass"); IMap map = mapSO.get_Map(mapServer.DefaultMapName); Log.Write("Layers map established", "myclass"); //int layerIndex = -1; IFeatureLayer fLayer = map.get_Layer(0) as IFeatureLayer;The map was created with direct connect, I don't know if that makes a difference.

So far, the arcgis connects, and everything goes fine, but it stops here:

IMap map = mapSO.get_Map(mapServer.DefaultMapName);

I checked mapServer.DefaultMapName, and it returns "Layers" so that's all correct.

mapSO also works because mapServer and mapSO are the same object basically.

So how is there a null here?

My log prints out an exception and never reaches "layers map established".

The exception:

Object reference not set to an instance of an object.I've tried a few other maps too and it doesn't work. But this code is straight from sample code I've seen on ESRI website, and it works for ESRI.

I'm using ArcGIS 9.3.1.



أكثر...
 
أعلى