iroh

E_FAIL when calling IImageServer.Initialize()

Discussion created by iroh on Dec 16, 2011
Latest reply on Jan 12, 2012 by iroh
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();
        
            [STAThread()]
            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(
                    "esriDataSourcesGDB.FileGDBWorkspaceFactory");
                IWorkspaceFactory workspaceFact = (IWorkspaceFactory)Activator.CreateInstance
                    (factoryType);
                IWorkspace workspace = workspaceFact.OpenFromFile(@"c:\temp\fgdb.gdb", 0);
                saveas.SaveAs("clipfromimageserverlayer", workspace, "gdb");
                
                m_AOLicenseInitializer.ShutdownApplication();
            }
        }
    }


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."
      Source="ESRI.ArcGIS.Carto"
      ErrorCode=-2147467259
      StackTrace:
           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()
      InnerException:

Outcomes