【发布时间】: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