【问题标题】:SSIS Script Task with Microsoft.Exchange.WebServices带有 Microsoft.Exchange.WebServices 的 SSIS 脚本任务
【发布时间】:2019-03-12 21:04:58
【问题描述】:

这可能是this 帖子的重复问题,但是我的错误不同并且可读性差得多。

现在,我有一个仅包含脚本任务的 SSIS 包。在该脚本任务中,我引用了 Microsoft.Exchange.WebServices.dll 并将其包含在命名空间中。

只要我不使用 WebServices 中定义的任何方法和类,脚本就会完美运行。但是,每当我使用它们时,整个脚本都会失败,甚至不会在第一行到达断点...它还会引发以下错误:

在 System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) 在 System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(对象 obj,对象 [] 参数,对象 [] 参数) 在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj,BindingFlags invokeAttr,Binder binder,Object[] 参数,CultureInfo 文化) 在 System.RuntimeType.InvokeMember(字符串名称、BindingFlags bindingFlags、Binder binder、Object 目标、Object[] providedArgs、ParameterModifier[] 修饰符、CultureInfo 文化、String[] namedParams) 在 Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()

有什么想法吗?当我在这个 SSIS 脚本任务之外(在它自己的项目中)运行我的相同代码时,它工作正常。

更新

我正在更新这篇文章,以包含更多可能有用的信息。我的脚本任务中的代码如下所示:

public void Main()
{
    string _SharedBox = "user@domain.com";
    ExchangeService service = new ExchangeService();
    service.AutodiscoverUrl(_SharedBox);
    service.UseDefaultCredentials = true;
    //... goes on, but the rest is commented out for now.
}

我认为Microsoft.Exchange.WebServices 可能没有正确包含,这就是问题所在,但我不确定它有什么问题。我的 DLL 位于 VS 解决方案内部,但位于 SSIS 项目外部。然后我将它添加为脚本任务中的参考 - 这是我不确定的部分。我最初尝试通过 NuGet 包包含 WebServices,但是,我开始意识到您不能在脚本任务中使用 NuGet。这是我的解决方案在脚本任务中的样子:

提前感谢您的帮助!

【问题讨论】:

  • the entire script fails and won't even make it to a break point on the first line 表示脚本在验证阶段(或 PreExecute 阶段)失败,您必须提供脚本代码和真正的错误消息,因为您提供的是错误 StackTrace 而不是消息。
  • @Hadi 我运行它时得到的唯一其他消息是:目标调用引发了异常。我不确定在哪里可以查找此脚本产生的错误。我将更新我的帖子并将代码添加到我的脚本任务中。
  • @DarrylHuffman 只需将service.UseDefaultCredentials = true; 移动到service.AutodiscoverUrl(_SharedBox); 之前,如提供的答案中所述

标签: c# sql-server ssis exchangewebservices script-task


【解决方案1】:

更新 1

尝试两件事:

  • Run the package in 32-bit mode (因为可能只有 32 位程序集在 GAC 中注册。)
  • Microsoft.Exchange.WebServices.dll Copy Local 属性设置为True

读取主要异常

根据您的 cmets,抛出的异常是:

目标调用抛出异常

脚本代码抛出异常时显示的一般错误消息。要阅读主要错误消息,您可以在代码中添加 try catch 子句并使用 Dts.FireError() 方法抛出真正的异常。

public void Main()
{
    try{

        string _SharedBox = "user@domain.com";
        ExchangeService service = new ExchangeService();
        service.AutodiscoverUrl(_SharedBox);
        service.UseDefaultCredentials = true;
        //... goes on, but the rest is commented out for now.
        Dts.TaskResult = (int)ScriptResult.Success;

    }catch(Exception ex){

        Dts.FireError(0,"An error occured", ex.Message,String.Empty, 0);
        Dts.TaskResult = (int)ScriptResult.Failure;

    }


}

试图找出问题

搜索了一段时间后,我认为异常是在以下行中抛出的:

service.AutodiscoverUrl(_SharedBox);

尝试将service.UseDefaultCredentials = true; 放在service.AutodiscoverUrl(_SharedBox); 之前,因为必须在使用AutoDiscoverUrl() 方法之前定义凭据。

此外,您可以查看以下链接,它可以为您提供有关使用 ExchangeService 阅读电子邮件的更多信息:

【讨论】:

  • 感谢您的帮助。不幸的是,我不认为这是问题所在……它的执行似乎还不够远,甚至无法进入异常。这让我想知道我是否能够在 SSIS 脚本任务中添加对 DLL 的引用。当我使用 Microsoft.Exchange.WebServices 命名空间中的任何方法时,该任务只是抛出异常而没有任何细节。我尝试添加Dts.Events.FireError,但是,由于脚本没有真正运行,它似乎没有冒泡。
  • @DarrylHuffman 尝试在 32 位模式下运行包可能是 64 位问题 dll 未注册
  • @DarrylHuffman 你试过在 32 位模式下运行包吗?
猜你喜欢
  • 2014-09-27
  • 1970-01-01
  • 2015-11-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多