gpt4 book ai didi

c# - 带 SSIS 包的 Winscp 给出 System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)

转载 作者:太空狗 更新时间:2023-10-29 17:41:30 24 4
gpt4 key购买 nike

使用 nuget 安装程序安装了 WinSCP .net。

Visual Studio 2013

SSIS 投标 2012

项目引用正确 - 指向已安装的 DLL

项目包含一个脚本,它是来自 winscp 站点的示例代码的精简版本。在尝试实例化 SessionOptions 对象的第一行失败。如果我删除 SessionOptions 对象就没问题。

按照说明在 GAC 中注册了 winscpnet.dll。

在 visual studio ssis 调试器中启动脚本,得到这个:

at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) 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()

    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;
}

添加流程和过程的屏幕截图

Heres the package Script details Error when I run it Debug spew

更新:修改代码如下...完全相同的结果

        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;
}

最佳答案

当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 引用,这是此错误的原因。

希望这有用!!

关于c# - 带 SSIS 包的 Winscp 给出 System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29281399/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com