![](/img/trans.png)
[英]Could not load file or assembly 'BouncyCastle.Crypto, Version=1.8.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies
[英]C#: Could not load file or assembly 'OpenPop, Version=2.0.4.369, Culture=neutral, PublicKeyToken=null' or one of its dependencies
我正在嘗試使用OpenPop.NET訪問gmail帳戶,但是即使使用基本測試代碼,我也會收到以下錯誤消息。
錯誤:System.Reflection.TargetInvocationException:調用目標已拋出異常。 ---> System.IO.FileNotFoundException:無法加載文件或程序集'OpenPop,Version = 2.0.4.369,Culture = neutral,PublicKeyToken = null'或其依賴項之一。 該系統找不到指定的文件。 文件名:'OpenPop,Version = 2.0.4.369,Culture = neutral,PublicKeyToken = null'at ST_1694f4bcdf2a4068ae871201a2216457.csproj.ScriptMain.Main()
警告:裝配綁定日志記錄已關閉。 要啟用程序集綁定失敗日志記錄,請將注冊表值[HKLM \\ Software \\ Microsoft \\ Fusion!EnableLog](DWORD)設置為1.注意:程序集綁定失敗日志記錄會導致一些性能損失。 要關閉此功能,請刪除注冊表值[HKLM \\ Software \\ Microsoft \\ Fusion!EnableLog]。
---內部異常堆棧跟蹤的結束---在System.Reflection.RuntimeMethodInfo.Invoke的System.RuntimeMethodHandle._InvokeMethodFast(Object target,Object []參數,SignatureStruct&sig,MethodAttributes methodAttributes,RuntimeTypeHandle typeOwner)中(Object obj,BindingFlags invokeAttr) System.RuntimeType.InvokeMember(String name)上的System.Reflection.RuntimeMethodInfo.Invoke(Object obj,BindingFlags invokeAttr,Binder binder,Object []參數,CultureInfo文化),Binder binder,Object []參數,CultureInfo文化,布爾值skipVisibilityChecks) ,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的Windows 7計算機上的SQL Server Business Intelligence Development Studio 2008中的SSIS包中執行此操作.OpenPop dll和引用它的腳本任務都是在3.5中構建的。 我已經研究了幾天,但一直沒能找到任何可以修復它的東西。 我嘗試從源重新編譯OpenPop dll並多次刪除和重新添加引用。
我目前正在使用的代碼發布如下:
Pop3Client client = new Pop3Client();
try
{
client.Connect("pop.gmail.com", 995, true);
try
{
client.Authenticate("user@domain.com", "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;
先感謝您。
我也遇到過這個問題,解決方案實際上非常簡單。 您必須將引用的程序集安裝到運行程序包的服務器的GAC上。
1)驗證裝配是否已簽名,如果您創建了自己的裝配,請對其進行簽名。
2)使用Visual Studio的SDK工具中的gacutil.exe
將DLL安裝到GAC。 有關更多信息,請參見如何:將程序集安裝到全局程序集緩存中 。
3)從腳本任務中引用相同的DLL
瞧,它現在應該完美運作!
將DLL安裝到GAC(全局程序集緩存)
1)Visual Studio命令提示符=>以管理員身份運行
2)gacutil / i“dll文件路徑”
3)在C:\\ Windows \\ system32上看到程序集
它還將解決SSIS腳本任務中缺少的dll或“無法加載文件或程序集”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.