【问题标题】:install newtonsoft to global assembly cache for use in SSIS Script task将 newtonsoft 安装到全局程序集缓存以用于 SSIS 脚本任务
【发布时间】: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"));
}

【问题讨论】:

    标签: c# ssis json.net gac


    【解决方案1】:

    如果您使用Reflection,则无需在 GAC 中安装它,您只需确保 DLL 位于您在代码中引用的服务器上的同一路径中

    C:\Newtonsoft.Json.12.0.3\lib\net45\

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-03
      • 1970-01-01
      • 2011-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多