“对 COM 组件的调用返回了错误 HRESULT E_FAIL。ERROR 000622:”这个错误困扰了我一整天,网上找了好多解决方案,但统统都以失败告终。下面将网上找的纷纷列出来,并分析下失败的原因:
1.权限错误://初始化许可
IAoInitialize m_AoInitialize = new AoInitializeClass(); esriLicenseStatus licenseStatus = esriLicenseStatus.esriLicenseUnavailable;
licenseStatus = m_AoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcInfo); //3DAnalyst 扩展模块授权 m_AoInitialize.CheckOutExtension(esriLicenseExtensionCode.esriLicenseExtensionCode3DAnalyst);

我设置的权限为ARCINFO,不可能是此错误。(注:后来做AE开发的时候发现,虽然权限为ACRINfo,也会出现此错误 ,原因是在项目里面添加了ARCINFO 权限,又添加了liscense控件,可能是两个权限有冲突吧,去掉项目里AECINFO权限的上的勾或吧liscense控件删掉,呵呵,错误消失了),得改口了,有可能出现此错误。

2.以gp工具中的merge工具进行示例分析:
(1)、当参数input所表示的要素类型不一致的时候会出现“对 COM 组件的调用返回了错误 HRESULT E_FAIL”提示。
(2)、当参数output所表示的要素已存在,且gp工具的overwrite属性设置为false的时候也会出现此提示,可以将overwrite
属性设置为true,这样就可以重写output而不会出现此问题。
(3)、input各要素之间没有用分号分隔。
View Code
  1 private void CbxAddItems(ComboBox cbo, esriGeometryType geometryType)
  2 {
  3 IFeatureLayer featureLayer;
  4 IEnumLayer layers = GetLayers();
  5 if (layers == null) return;
  6 layers.Reset();
  7 ILayer layer = layers.Next();
  8 while (layer != null)
  9 {
 10 if (layer is IFeatureLayer)
 11 {
 12 featureLayer = layer as IFeatureLayer;
 13 if (featureLayer.FeatureClass.ShapeType == geometryType)
 14 {
 15 cbo.Items.Add(layer.Name);
 16 }
 17 }
 18 layer = layers.Next();
 19 }
 20 }
 21 
 22 private void CbxAddItems(ComboBox cbo, esriGeometryType geometryType, IFeatureLayer inputLayer)
 23 {
 24 esriGeometryType inputGeometryType = inputLayer.FeatureClass.ShapeType;
 25 string inputName = inputLayer.Name;
 26 IFeatureLayer featureLayer;
 27 IEnumLayer layers = GetLayers();
 28 if (layers == null) return;
 29 layers.Reset();
 30 ILayer layer = layers.Next();
 31 while (layer != null)
 32 {
 33 if (layer is IFeatureLayer)
 34 {
 35 featureLayer = layer as IFeatureLayer;
 36 if (featureLayer.Name == inputName) goto label1;
 37 if (featureLayer.FeatureClass.ShapeType == geometryType)
 38 {
 39 cbo.Items.Add(layer.Name);
 40 }
 41 }
 42 label1: layer = layers.Next();
 43 }
 44 }
 45 
 46 private void CbxAddItems(ComboBox cbo, IFeatureLayer inputLayer)
 47 {
 48 esriGeometryType inputGeometryType = inputLayer.FeatureClass.ShapeType;
 49 string inputName = inputLayer.Name;
 50 IFeatureLayer featureLayer;
 51 IEnumLayer layers = GetLayers();
 52 if (layers == null) return;
 53 layers.Reset();
 54 ILayer layer = layers.Next();
 55 while (layer != null)
 56 {
 57 if (layer is IFeatureLayer)
 58 {
 59 featureLayer = layer as IFeatureLayer;
 60 if (featureLayer.Name == inputName) goto label1;
 61 cbo.Items.Add(layer.Name);
 62 }
 63 label1: layer = layers.Next();
 64 }
 65 }
 66 
 67 private void CbxAddItemsForErase(ComboBox cbo, IFeatureLayer inputLayer)
 68 {
 69 esriGeometryType inputGeometryType = inputLayer.FeatureClass.ShapeType;
 70 string inputName = inputLayer.Name;
 71 IFeatureLayer featureLayer;
 72 IEnumLayer layers = GetLayers();
 73 if (layers == null) return;
 74 layers.Reset();
 75 ILayer layer = layers.Next();
 76 while (layer != null)
 77 {
 78 if (layer is IFeatureLayer)
 79 {
 80 featureLayer = layer as IFeatureLayer;
 81 if (featureLayer.Name == inputName) goto label1;
 82 esriGeometryType overlayGeometryType = featureLayer.FeatureClass.ShapeType;
 83 
 84 if (inputGeometryType == esriGeometryType.esriGeometryPoint )
 85 {
 86 if (overlayGeometryType == esriGeometryType.esriGeometryPoint || overlayGeometryType == esriGeometryType.esriGeometryMultipoint)
 87 {
 88 cbo.Items.Add(layer.Name);
 89 }
 90 }
 91 else if (inputGeometryType == esriGeometryType.esriGeometryPolyline)
 92 {
 93 if (overlayGeometryType == esriGeometryType.esriGeometryPolyline || overlayGeometryType == esriGeometryType.esriGeometryPolygon)
 94 {
 95 cbo.Items.Add(layer.Name);
 96 }
 97 }
 98 else if (inputGeometryType == esriGeometryType.esriGeometryPolygon)
 99 {
100 if (overlayGeometryType == esriGeometryType.esriGeometryPolygon)
101 {
102 cbo.Items.Add(layer.Name);
103 }
104 }
105 else
106 {
107 return;
108 }
109 
110 }
111 label1: layer = layers.Next();
112 }
113 }
114 
115 private void CbxAddItemsForIdentity(ComboBox cbo, IFeatureLayer inputLayer)
116 {
117 esriGeometryType inputGeometryType = inputLayer.FeatureClass.ShapeType;
118 string inputName = inputLayer.Name;
119 IFeatureLayer featureLayer;
120 IEnumLayer layers = GetLayers();
121 if (layers == null) return;
122 layers.Reset();
123 ILayer layer = layers.Next();
124 while (layer != null)
125 {
126 if (layer is IFeatureLayer)
127 {
128 featureLayer = layer as IFeatureLayer;
129 if (featureLayer.Name == inputName) goto label1;
130 esriGeometryType overlayGeometryType = featureLayer.FeatureClass.ShapeType;
131 if (overlayGeometryType == inputGeometryType || overlayGeometryType == esriGeometryType.esriGeometryPolygon)
132 {
133 cbo.Items.Add(layer.Name);
134 }
135 }
136 label1: layer = layers.Next();
137 }
138 }
139 
140 private void CbxAddItemsForSymDiff(ComboBox cbo, IFeatureLayer inputLayer)
141 {
142 esriGeometryType inputGeometryType = inputLayer.FeatureClass.ShapeType;
143 string inputName = inputLayer.Name;
144 IFeatureLayer featureLayer;
145 IEnumLayer layers = GetLayers();
146 if (layers == null) return;
147 layers.Reset();
148 ILayer layer = layers.Next();
149 while (layer != null)
150 {
151 if (layer is IFeatureLayer)
152 {
153 featureLayer = layer as IFeatureLayer;
154 if (featureLayer.Name == inputName) goto label1;
155 esriGeometryType overlayGeometryType = featureLayer.FeatureClass.ShapeType;
156 if (overlayGeometryType == inputGeometryType)
157 {
158 cbo.Items.Add(layer.Name);
159 }
160 }
161 label1: layer = layers.Next();
162 }
163 }

 

以上代码严格控制了输入要素和叠加要素的类型,所以也不会可能是此错误

找了好久终于找到了错误的根源。原来是
IGpValueTableObject vtobject = new GpValueTableObjectClass();
            vtobject.SetColumns(1);
            object row = "";
            //加入输入图层
            row = GetFeatureLayer(strInputLayer);
            vtobject.AddRow( ref row);
            //加入输出图层
            row = GetFeatureLayer(strOverLayLayer);
            vtobject.AddRow(ref row);

            IVariantArray pVarArry = new VarArrayClass();
            pVarArry.Add(vtobject);
            string outputFullPath = System.IO.Path.Combine(strOutputPath, strInputLayer + "_" + strOverLayLayer + "_" + "Intersect");
            pVarArry.Add(outputFullPath);
          
            pVarArry.Add(strOutputAttributeType);
            pVarArry.Add(tolerance);
            pVarArry.Add(strOutputFeatureType);
IGeoProcessorResult results = gp.Execute("Union_analysis", pVarArray, null) as IGeoProcessorResult;

pVarVarry的添加参数的参数顺序在此捣乱,一定要按照规定顺序才有用。