AE二次开发引发异常“System.Runtime.InteropServices.COMException” 异常来自 HRESULT:0x80040351

@SOAR 2017-06-06 10:57:08

开发环境vs2015+AE10.2,刚开始接触
//加载Shp格式文件
public ILayer AddShap(string strFileName)
{
string WorkSpacePath = System.IO.Path.GetDirectoryName(strFileName);
string strShapeFileNmeWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(strFileName);
IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(WorkSpacePath, 0);

IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(strShapeFileNmeWithoutExtension);

IDataset pDataset = pFeatureClass as IDataset;
IFeatureLayer pFeatureLayer = new FeatureLayer();

pFeatureLayer.Name = pDataset.Name;
ILayer pLayer = pFeatureLayer as ILayer;

return pLayer;
}
//将图层添加到MapControl的Map对象
ILayer mLayer =AddShap(strrPath);
axMapControl1.Map.AddLayer(mLayer);


语句: IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(strShapeFileNmeWithoutExtension);
引发异常:“System.Runtime.InteropServices.COMException”类型的未经处理的异常在 .exe 中发生
其他信息: 异常来自 HRESULT:0x80040351
怎样解决?还请各路英雄指点迷津!!
...全文
1854 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Trustport 2020-03-09
  • 打赏
  • 举报
回复
你是不是把扩展名也列进去了,OpenFeatureClass打开shapefile不能有扩展名
SoulRed 2017-06-06
  • 打赏
  • 举报
回复
IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(strShapeFileNmeWithoutExtension); 拆分这一句,看看具体是哪个字段出了问题。
@SOAR 2017-06-06
  • 打赏
  • 举报
回复
IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(strShapeFileNmeWithoutExtension); 实参与形参类型不符,OpenFeatureClass()形参为不加后缀的文件名,传递的实参错误引起的常: 引发异常:“System.Runtime.InteropServices.COMException”类型的未经处理的异常在 .exe 中发生 其他信息: 异常来自 HRESULT:0x80040351

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧