【发布时间】:2021-03-20 08:09:43
【问题描述】:
我正在使用 newtonsoft dll 来解析 SSIS 脚本任务中的 json 数据。这在我的本地计算机上按预期工作,但是当部署到 SQL Server 并从 SQL Server 作业运行时会引发错误:
“调用目标抛出异常”
我正在尝试将 newtonsoft dll 安装到全局程序集缓存。为了做到这一点,我必须将 Newtonsoft 安装到服务器上,例如它保存到 C 目录。然后使用 gacutil 将其安装到全局程序集缓存。
C:\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll
gacutil /i Newtonsoft.Json.dll
在脚本任务 C# 代码中引用下面的 dll?
static ScriptMain()
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
}
static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
string path = @"C:\Newtonsoft.Json.12.0.3\lib\net45\";
return System.Reflection.Assembly.LoadFile(System.IO.Path.Combine(path, "Newtonsoft.Json.dll"));
}
【问题讨论】: