2012-04-03 98 views
3

我正在嘗試使用OpenPop.NET訪問gmail帳戶,但是我即使使用基本測試代碼也會收到以下錯誤消息。C#:無法加載文件或程序集'OpenPop,Version = 2.0.4.369,Culture = neutral,PublicKeyToken = null'或其依賴項之一

Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'OpenPop, Version=2.0.4.369, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. File name: 'OpenPop, Version=2.0.4.369, Culture=neutral, PublicKeyToken=null' at ST_1694f4bcdf2a4068ae871201a2216457.csproj.ScriptMain.Main()

WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

--- End of inner exception stack trace --- at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()

我試圖與.NET Framework 3.5的和4這兩個OpenPop DLL和被引用它的腳本任務來完成在SSIS包在SQL Server商業智能開發Studio 2008的Windows 7的機器上正在建造3.5。我一直在研究這幾天,但一直沒能找到任何可以解決問題的方法。我曾嘗試從源代碼重新編譯OpenPop DLL,並多次刪除和重新添加引用。

目前與我下面張貼工作代碼:

 Pop3Client client = new Pop3Client(); 

     try 
     { 
      client.Connect("pop.gmail.com", 995, true); 

      try 
      { 
       client.Authenticate("[email protected]", "mypassword"); 
       Console.WriteLine("Success"); 
       client.Disconnect(); 
      } 
      catch 
      { 
       Console.WriteLine("Failed to authenticate"); 
       Dts.TaskResult = (int)ScriptResults.Failure; 
       return; 
      } 
     } 
     catch 
     { 
      Console.WriteLine("Failed to connect"); 
      Dts.TaskResult = (int)ScriptResults.Failure; 
      return; 
     } 

     Dts.TaskResult = (int)ScriptResults.Success; 

預先感謝您。

回答

7

我也遇到過這個問題,解決方案其實很簡單。您必須將引用的程序集安裝到運行該程序包的服務器的GAC上。

1)驗證程序集是否已簽名,如果創建了自己的程序集,請對其進行簽名。

2)使用Visual Studio SDK工具中的gacutil.exe將DLL安裝到GAC。欲瞭解更多信息,請參閱How to: Install an Assembly into the Global Assembly Cache

3)從你的腳本任務

瞧引用同一個DLL,它現在應該很好地工作!

+0

注:將Gacutil.exe僅用於開發目的,不應該用於將生產組件安裝到全局程序集緩存中。 – toha 2016-02-16 03:50:12

1

安裝你的DLL到GAC(全局程序集緩存)

1)Visual Studio命令提示符=>運行作爲管理員聯繫

2)GACUTIL /我 「dll文件路徑」

3)看大會C:\ WINDOWS \ SYSTEM32 \

它也將解決DLL丟失或在SSIS腳本任務「無法加載文件或程序集」