2014-07-23 74 views
2

我試圖執行用VBScript一個腳本,在C#類庫項目運行VBScript C#

using System.Web.UI; //reference added at top 

MSScriptControl script = new ScriptControl(); 
script.Language = "VBScript"; 
script.AddObject("Repository", connectToDB.GetRepository); 

我得到以下編譯錯誤:

Error CS0246: The type or namespace name 'MSScriptControl' could not be found (are you missing a using directive or an assembly reference?)

任何想法?

+0

他們是同一個命名空間下?或者您是否正確添加了引用? – iJay

+0

@IJ,我正確添加了它 - 只是想澄清添加了該引用。有任何想法嗎? – user3165438

回答

1
  1. 添加 「Microsoft腳本控制1.0」 的COM引用到您的項目。
  2. using Microsoft.VisualBasic;
  3. 使用此代碼:​ ​

    MSScriptControl.ScriptControl script = new MSScriptControl.ScriptControl(); 
    script.Language = "VBScript"; 
    script.AddObject("Repository", connectToDB.GetRepository); 
    
1

我相信

MSScriptControl script = new ScriptControl(); 

應該

MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControl();