使用nuget安装程序安装WinSCP .net。
Visual Studio 2013
SSIS BIDS 2012
项目引用是正确的 - 指向已安装的DLL
Project包含一个脚本,它是winscp站点的示例代码的精简版本。尝试实例化SessionOptions对象的第一行失败。如果我删除SessionOptions对象,那很好。
按照说明在GAC中注册winscpnet.dll。
在visual studio ssis调试器中启动脚本,得到这个:
at System.RuntimeMethodHandle.InvokeMethod(Object target,Object [] 参数,签名sig,布尔构造函数)at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object []参数,Object []参数)at System.Reflection.RuntimeMethodInfo.Invoke(Object obj,BindingFlags invokeAttr,Binder binder,Object []参数,CultureInfo文化)
在System.RuntimeType.InvokeMember(String name,BindingFlags bindingFlags,Binder binder,Object target,Object [] providedArgs, ParameterModifier []修饰符,CultureInfo文化,String [] namedParams)at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
public void Main()
{
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
// To setup these variables, go to SSIS > Variables.
// To make them accessible from the script task, in the context menu of the task,
// choose Edit. On the Script task editor on Script page, select ReadOnlyVariables,
// and tick the below properties.
HostName = "",
UserName = "",
Password = "",
SshHostKeyFingerprint = ""
};
bool fireAgain = false;
Dts.Events.FireInformation(0, null,
string.Format("Upload of succeeded"),
null, 0, ref fireAgain);
Dts.TaskResult = (int)DTSExecResult.Success;
}
添加流程和流程的屏幕提示
更新:修改代码如下......完全相同的结果
public void Main()
{
bool fireAgain = false;
try
{
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
// To setup these variables, go to SSIS > Variables.
// To make them accessible from the script task, in the context menu of the task,
// choose Edit. On the Script task editor on Script page, select ReadOnlyVariables,
// and tick the below properties.
HostName = "",
UserName = "",
Password = "",
SshHostKeyFingerprint = ""
};
}
catch (Exception ex)
{
Dts.Events.FireInformation(0, null,
ex.InnerException.Message,
null, 0, ref fireAgain);
}
Dts.TaskResult = (int)DTSExecResult.Success;
}
答案 0 :(得分:13)
在SSIS脚本任务中使用第三方DLL时,我们需要执行GAC。
请打开命令提示符。
cd "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools"
运行以下命令。
gacutil -i <"Path of WinSCP DLL">
运行GAC命令后,Scrip任务应按预期运行。在运行时,SSIS无法获取DLL引用,这是导致此错误的原因。
希望这有效!!
答案 1 :(得分:1)
我知道这是一个老问题,但希望能有所帮助。基本上,您需要的是public void main
之外的这段代码。
public class example
{
static ScriptMain()
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
}
static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
if (args.Name.Contains("WinSCPnet"))
{
string path = @"Path to DLL";
return System.Reflection.Assembly.LoadFile(System.IO.Path.Combine(path, "WinSCPnet.dll"));
}
return null;
}
public void Main()
{ can now use DLL things in here}
}
请添加using WinSCP;
并将其添加到您的引用中。祝好运。
答案 2 :(得分:0)
在使用try catch块进行挖掘并在stacktrace的帮助下,在C#委托事件调用中遇到了相同的异常,我发现其中一个事件处理程序方法引发了一个异常。修复后,它开始正常工作。