我正在使用VS 2017和SQL Server 2016来完成这项工作。我创建了一个脚本任务,尝试使用SendGrid发送电子邮件。如果我在脚本任务中放置一个断点,则执行SSIS程序包并接收电子邮件不会有问题。但是,如果仅执行该程序包,则整个程序包仍然可以成功执行,但是我无法收到电子邮件,我怀疑脚本任务没有得到执行。以下是我的脚本任务的代码
public void Main()
{
string User_Email = Dts.Variables["User::UserEmail"].Value.ToString();
try
{
if (!File.Exists(Dts.Variables["User::OutputPath"].Value.ToString()))
throw new FileNotFoundException();
File.Copy(Dts.Variables["User::OutputPath"].Value.ToString(), Dts.Variables["User::DestinationPath"].Value.ToString() + Dts.Variables["User::co_num"].Value.ToString() + ".pdf", true);
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
SendGridMailHelper.SendOrderVerification(User_Email, "user name");
}
catch (FileNotFoundException)
{
MessageBox.Show("The file is not found in the specified location");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Dts.TaskResult = (int)ScriptResults.Success;
}
static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
if (args.Name.Contains("SendGrid"))
{
string path = @"F:\DLL\";
return System.Reflection.Assembly.LoadFile(System.IO.Path.Combine(path, "SendGrid.dll"));
}
if (args.Name.Contains("System.Net.Http"))
{
string path = @"F:\DLL\";
return System.Reflection.Assembly.LoadFile(System.IO.Path.Combine(path, "System.Net.Http.dll"));
}
if (args.Name.Contains("Newtonsoft.Json"))
{
string path = @"F:\DLL\";
return System.Reflection.Assembly.LoadFile(System.IO.Path.Combine(path, "Newtonsoft.Json.dll"));
}
return null;
}
为了安全起见,我检查了Windows日志,并在运行程序包时未添加检查点时显示了运行时错误。但是,我无法弄清楚这意味着什么。任何想法都会非常有帮助。谢谢。
应用程序:DtsDebugHost.exe 框架版本:v4.0.30319 说明:由于未处理的异常,进程已终止。 异常信息:System.MissingMethodException 在ST_b240be27e55248ea869be51aa06a2018.SendGridMailHelper + <_ SendEmail> d__7.MoveNext() 在System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start [[ST_b240be27e55248ea869be51aa06a2018.SendGridMailHelper + <__ SendEmail> d__7,ST_b240be27e55248ea869be51aa06a2018,Version = 1.0.6877.42064,Culture = neutral,Public(Ref <= Null)]中 在ST_b240be27e55248ea869be51aa06a2018.SendGridMailHelper._SendEmail(System.Collections.Generic.List`1,System.Object,System.String) 在ST_b240be27e55248ea869be51aa06a2018.SendGridMailHelper + d__9.MoveNext() 在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object,布尔值) 在System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object,布尔值) 在System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() 在System.Threading.ThreadPoolWorkQueue.Dispatch()