我正在尝试使用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(Object obj,BindingFlags invokeAttr)的System.RuntimeMethodHandle._InvokeMethodFast(Object target,Object []参数,SignatureStruct&sig,MethodAttributes methodAttributes,RuntimeTypeHandle typeOwner)中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;
Run Code Online (Sandbox Code Playgroud)
先感谢您.
我也遇到过这个问题,解决方案实际上非常简单.您必须将引用的程序集安装到运行程序包的服务器的GAC上.
1)验证装配是否已签名,如果您创建了自己的装配,请对其进行签名.
2)使用gacutil.exeVisual Studio的SDK工具将DLL安装到GAC .有关更多信息,请参见如何:将程序集安装到全局程序集缓存中.
3)从脚本任务中引用相同的DLL
瞧,它现在应该可以正常工作!