Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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 have just deployed an AGS-based application to our web server. This app worked great in development, but after deployment to the server I got the following error:

Unable to cast COM object of type 'System.__ComObject' to interface type 'ESRI.ArcGIS.Carto.IMapServerObjects'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{651521F3-AAFF-42B9-8C2D-1980625A13BF}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

The C# code generating this error is:

IServerContext context = som.CreateServerContext(ConfigurationManager.AppSettings["mapService"], "MapServer");
IMapServer mapServer = (IMapServer)context.ServerObject;
IMapServerObjects serverObjects = (IMapServerObjects)mapServer;

For some reason, the IMapServer instance cannot be casted to IMapServerObjects. What could be wrong?

share|improve this question

migrated from Sep 15 '11 at 22:04

This question came from our site for professional and enthusiast programmers.

Is the service based on an MSD? If so, this might be the issue: – Kirk Kuykendall Jun 14 '10 at 17:29
Yes. I had deployed the map service via ArcMap, not realizing that it creates an MSD-based service. Problem solved. – nw1 Jun 15 '10 at 13:22
up vote 3 down vote accepted

The solution is to deploy the map service as an MXD. The MSD only supports a subset of ArcObjects.

share|improve this answer

In getting ready for ArcGIS Server 10.1 you may need to prepare yourself for MSD only MapServices. The recommend path forward is to use IMapServerDataAccess since you will no longer have IMapServerObjects. However, if you're like me, and really miss out on IMapServerObjects particular it's ability to provide you an IMap object, there's a workaround! This is based on the fact that ArcGIS Server deploys a similarly named MXD with the MSD. By finding out the name of the MXD you can use the IMapDocument object to open and from there, get your IMap object.

// C++ ArcObjects code sample

HRESULT GetIMap(IServerObjectHelper *pIServerObjectHelper, IMap **ppIMap)
    HRESULT hResult = S_OK;

    CComPtr<IServerObjectHelper2> ptrIServerObjectHelper2;
    pIServerObjectHelper->QueryInterface(IID_IServerObjectHelper2, (void**) &ptrIServerObjectHelper2);

    CComPtr<IPropertySet> ptrIPropertySet;
    hResult = ptrIServerObjectHelper2->get_ServerObjectProperty(&ptrIPropertySet);

    CComVariant varFilePath;
    hResult = ptrIPropertySet->GetProperty(CComBSTR("filePath"), &varFilePath);

    CComBSTR bstrMxdPath;
    LPTSTR pSlash = _tcsrchr(V_BSTR(&varFilePath), '\\');
    LPTSTR pExt = _tcsrchr((pSlash != NULL) ? pSlash : V_BSTR(&varFilePath), '.');
    bstrMxdPath.Append(V_BSTR(&varFilePath), (int) (pExt - V_BSTR(&varFilePath)));

    CComPtr<IMapDocument> ptrIMapDocument;
    hResult = ptrIMapDocument.CoCreateInstance(CLSID_MapDocument);
    hResult = ptrIMapDocument->Open(bstrMxdPath, CComBSTR(""));

    CComPtr<IMap> ptrIMap;
    ptrIMap = NULL;
    hResult = ptrIMapDocument->get_Map(0, &ptrIMap);
    *ppIMap = ptrIMap.Detach();
    return S_OK;
share|improve this answer

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.