C#:无法加载文件或程序集 'OpenPop, Version=2.0.4.369, Culture=neutral, PublicKeyToken=null' 或其依赖项之一

标签 c# ssis openpop

我正在尝试使用 OpenPop.NET 访问 gmail 帐户,但即使使用基本测试代码,我也会收到以下错误消息。

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 的 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。有关详细信息,请参阅 How to: Install an Assembly into the Global Assembly Cache .

3) 从您的脚本任务中引用相同的 DLL

瞧,它现在应该可以完美运行了!

关于C#:无法加载文件或程序集 'OpenPop, Version=2.0.4.369, Culture=neutral, PublicKeyToken=null' 或其依赖项之一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9999441/

相关文章:

sql-server - “Microsoft.ACE.OLEDB.16.0”提供程序未在本地计算机上注册。 (系统.数据)

c# - TFS API - 如何独立于它们属于哪个构建定义来查询构建

c# - 是否可以通过静态方法访问实例变量?

c# - 部署到 Azure 后 API 连接字符串不起作用

ssis - 有人可以帮助解释一些新的 SSIS 2012 属性吗?

mysql - 从 MS SQL 导入 MYSQL 时 SSIS 包出错

c# - IIS 后台线程和 SignalR

c# - 如何在 OpenPOP 中立即删除邮件

c# - OpenPop - 获取电子邮件详细信息 c#

c# - 如何使用 pop3 c# 从 Yahoo mail 中读取最新的电子邮件