2012-01-10 66 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; 
相關問題