2012-01-10 68 views
0

我写了一个外部应用程序来驱动autocad与一个为COM注册的dll。我按照this codes写我的应用程序,但是我已经取代了下面的代码用的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; 

回答

1

您创建的DocumentManager的第二个实例,并给它从第一个检索的对象的引用。我想你想用

dm.MdiActiveDocument = doc; 
相关问题