Search code examples
c#asp.netgisarcgisarcgis-server

MapResource object cast problem


I have an 'ArcGIS Server Internet' resource into my MapResourceManager called "MapResourceItem0" and is the third of other two resources.

I need to get the features of the layers in this resource, but I can't obtain the MapResource object

Either this method

IMapResource mapresource = mapresourcemanager1.GetResource(2);
        ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource graphics_mapresource =
            (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource)mapresource;

and this

 ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource graphicsresource = null;
        foreach (IGISFunctionality gisfunctionality in map1.GetFunctionalities())
        {

            if (gisfunctionality.Resource.Name == "MapResourceItem0")
            {

                graphicsresource = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource)
                    gisfunctionality.Resource;

            }
        }

are failing with the following error

System.InvalidCastException: Cannot cast an object from 'ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceInternet' to 'ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource'.

I don't understand, examples and documentation clearly states this is acceptable, what's wrong with that? I'm using arcgis server 10


Solution

  • I (luckily) do not have the web ADF installed. It is not possible to cast a ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceInternet to anything that needs the server context.

    But ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceInternet implements IMapResource so maybe you can do:

    IMapResource mapresource = mapresourcemanager1.GetResource(2);
    ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceInternet graphics_mapresource =
        (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceInternet)mapresource;