【发布时间】:2013-12-19 19:11:52
【问题描述】:
我正在为我的应用程序开发一个 AutoCAD 插件。我正在使用 AutoCAD 2012。插件打开 .NET 命名管道,因此我可以非常轻松地从我的桌面应用程序连接到它。
首先,我创建了一个界面。在这里
[ServiceContract]
public interface IConnector
{
[OperationContract]
[FaultContract(typeof(Exception))]
void GetPdfVersion(string filePath, string exportFilePath);
}
我的 AutoCAD 插件是从 IExtensionApplication 接口派生的,所以我写的 Initialize 方法
this.host = new ServiceHost(typeof(Printer), new[] { new Uri("net.pipe://localhost") });
this.host.AddServiceEndpoint(typeof(IConnector), new NetNamedPipeBinding(), "GetPdfVersion");
this.host.Open();
在其中一个功能中,我需要打开文档并对其进行处理。 所以,我写了以下代码
var docColl = Application.DocumentManager;
Document curDraw = null;
try
{
if (File.Exists(@"d:\1.dwg"))
{
curDraw = docColl.Open(@"d:\1.dwg", true, string.Empty);
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
但它会在 curDraw = docColl.Open(@"d:\1.dwg", true, string.Empty); 代码上引发 COM 异常,HRESULT=-2147418113
我需要 Document 对象来处理 dwg 文件。有什么方法可以解决这个错误吗?
【问题讨论】:
-
除了
docColl.Open之外,你有没有尝试过做其他事情?例如,关闭所有打开的文档。如果是这样,您遇到了什么错误? -
是的。当我尝试过时,发生了同样的错误。我刚刚找到了解决方案。我会尽快写的
标签: c# wcf named-pipes autocad autocad-plugin