ArcGISEngine中GP工具奇怪错误问题error(s) have been detected for layer

运行时环境:使用CADToGeodatabase工具执行DWG文件转gdb过程,多次执行(即执行完一个dwg转gdb,再执行另一个dwg转gdb),执行失败

错误描述:首先执行CADToGeodatabase工具需要先生成gdb工作空间,这个很简单没什么问题

IWorkspaceFactory2 pTargetWsf = new FileGDBWorkspaceFactoryClass();
IWorkspaceName pWorkspaceName = pTargetWsf.Create(sPath, sName, null, 0);
IWorkspace gdbWks = pTargetWsf.Open(pWorkspaceName.ConnectionProperties, 0);

然后执行CADToGeodatabase gp工具。

public static bool CADToGeodatabase(string cadPath,string gdbPath,ref string msg)
        {
            Geoprocessor gp = new Geoprocessor();
            object sev = null;
            try
            {
                CADToGeodatabase tool = new CADToGeodatabase();
                tool.input_cad_datasets = cadPath;
                tool.out_dataset_name = "CADDATASET";
                tool.out_gdb_path = gdbPath;
                tool.reference_scale = 1000;
                gp.Execute(tool, null);
                return true;
            }
            catch (Exception ex)
            {
                msg = gp.GetMessages(ref sev);
                return false;
            }
        }

问题来了,在gp.Execute(tool, null)处,第二次执行会抛出异常,通过查看msg,发现是因为有2072个注记转换失败,并且记录在了log文件中。

ERROR 000278: 2072 error(s) have been detected for layer 20181015142904. Errors are described in file GLC:\Users\用户\AppData\Local\Temp\GL201810151429040.log.log in your temp directory.
ERROR 000016: 2072 annotation(s) rejected
Failed to execute (CADToGeodatabase).

在temp文件夹下确实发现了log日志。

ArcGISEngine中GP工具奇怪错误问题error(s) have been detected for layer_第1张图片

 

后来发现官方实例用到gp工具的地方都是在类实例中使用,没在静态方法中使用。于是测试把gp工具不用静态调用,结果好了,而且每次在temp下都不会有日志存在。

 浅尝辄止:以后用gp工具最好不要放在静态调用

你可能感兴趣的:(ArcGISEngine中GP工具奇怪错误问题error(s) have been detected for layer)