I am using ArcGIS Engine and Developer Kit 10 on Windows 7. Specifically, I'm writing an ArcObjects console program using Visual C# Express 2008.

I am attempting connect to an image server via a URL (e.g. http://server/.../ImageServer), but I get an HRESULT E_FAIL exception when I call IImageServerLayer.Initialize(). The full message is "Error HRESULT E_FAIL has been returned from a call to a COM component." There isn't much information on this error. Any advice on what could be wrong? Here's my code:

using System;
using System.Collections.Generic;
using System.Text;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.DataSourcesRaster;
using ESRI.ArcGIS.GISClient;

namespace EngineConsoleApplication1
    class Program
        private static LicenseInitializer m_AOLicenseInitializer = new EngineConsoleApplication1.LicenseInitializer();

        static void Main(string[] args)
            //ESRI License Initializer generated code.
            m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeEngine },
            new esriLicenseExtensionCode[] { esriLicenseExtensionCode.esriLicenseExtensionCode3DAnalyst, esriLicenseExtensionCode.esriLicenseExtensionCodeNetwork, esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst, esriLicenseExtensionCode.esriLicenseExtensionCodeSchematics, esriLicenseExtensionCode.esriLicenseExtensionCodeMLE, esriLicenseExtensionCode.esriLicenseExtensionCodeDataInteroperability, esriLicenseExtensionCode.esriLicenseExtensionCodeTracking });
            //ESRI License Initializer generated code.
            //Do not make any call to ArcObjects after ShutDownApplication()

            //Create an image server layer by passing a URL.
            IImageServerLayer imageserverlayer = new ImageServerLayerClass();
            string URL = "http://vega/ArcGIS/rest/services/grandcanyon/ImageServer";
            imageserverlayer.Initialize(URL); // "Error HRESULT E_FAIL has been returned from a call to a COM component."

            //Get the raster from the image server layer.
            IRaster raster = imageserverlayer.Raster;

            //The raster from an image server is normally large; 
            //define the size of the raster.
            IRasterProps rasterProps = (IRasterProps)raster;
            IEnvelope clipEnvelope = new EnvelopeClass();
            clipEnvelope.PutCoords(779000, 9628000, 786000, 9634000);
            rasterProps.Extent = clipEnvelope;
            rasterProps.Width = 256;
            rasterProps.Height = 256;

            //Save the clipped raster to the file geodatabase.
            ISaveAs saveas = (ISaveAs)raster;
            Type factoryType = Type.GetTypeFromProgID(
            IWorkspaceFactory workspaceFact = (IWorkspaceFactory)Activator.CreateInstance
            IWorkspace workspace = workspaceFact.OpenFromFile(@"c:\temp\fgdb.gdb", 0);
            saveas.SaveAs("clipfromimageserverlayer", workspace, "gdb");


This code is based on http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//00010000047t000000.

Here's the exception detail provided by Visual C#'s error dialog:

System.Runtime.InteropServices.COMException was unhandled
  Message="Error HRESULT E_FAIL has been returned from a call to a COM component."
       at ESRI.ArcGIS.Carto.ImageServerLayerClass.Initialize(String ServiceURL)
       at EngineConsoleApplication1.Program.Main(String[] args) in C:\Users\brown\AppData\Local\Temporary Projects\EngineConsoleApplication1\Program.cs:line 35
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

3 Answers 3


I would try using ESRI.ArcGIS.RuntimeManager.Bind before license initialization, as shown here.

STAThread()] static void Main(string[] args)
    //Add runtime binding prior to any ArcObjects code in the static void Main() method.
    //ESRI License Initializer generated code.
    m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[]
    , new esriLicenseExtensionCode[]{}
    //ESRI License Initializer generated code.
    // Insert code here.
    //Do not make any call to ArcObjects after ShutDownApplication().

A few things you can try:

  • Make sure arcGIS accounts/groups have permissions to the c:\temp\ folder and the fgdb.gdb file.
  • Make sure the COM components exists on your machine. Try re-installing ArcObjects SDK and/or ArcEngine. It seems like the COM object in question might not be found.
  • In order to debug, try to isolate the code that's causing the error. You sometimes get a better, more descriptive error.

I solved this problem. It turns out the SOAP address needs to be used, which in my case is http://vega/ArcGIS/services/grandcanyon/ImageServer?wsdl. I obtained this address by going up a folder (http://vega/ArcGIS/rest/services/grandcanyon/ImageServer) and clicking on the "SOAP" link at the bottom. You also don't need the "?wsdl" suffix at the end of the address.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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