我编写了一个外部应用程序来驱动带有为 COM 注册的 dll 的 autocad。我已经按照这些代码编写了我的应用程序,但是我用 AddNumbers() 方法替换了以下代码:
public string OpenDWGFile(string MyDWGFilePath)
{
DocumentCollection dm = Application.DocumentManager;
Document doc = null;
if(File.Exists(MyDWGFilePath))
{
doc = dm.Open(MyDWGFilePath, false);
Application.DocumentManager.MdiActiveDocument = doc;
return "This file is exists";
}
else
return "This file is not exist";
}
但是当我运行我的应用程序时,autocad 软件会立即打开然后关闭,并且会显示此错误消息:调用目标已引发异常。
但如果我评论我的代码的以下行,则应用程序可以正常工作:
doc = dm.Open(MyDWGFilePath, false);
Application.DocumentManager.MdiActiveDocument = doc;