简体   繁体   English

将 newtonsoft 安装到全局程序集缓存以用于 SSIS 脚本任务

[英]install newtonsoft to global assembly cache for use in SSIS Script task

I am using newtonsoft dll to parse json data in SSIS script task.我正在使用 newtonsoft dll 来解析 SSIS 脚本任务中的 json 数据。 This works as expected on my local machine but when deployed to SQL Server and run from SQL Server job throws error:这在我的本地计算机上按预期工作,但是当部署到 SQL 服务器并从 SQL 服务器作业运行时会抛出错误:

"Exception has been thrown by target of an invocation" “调用的目标已引发异常”

I am trying to install newtonsoft dll to global assembly cache.我正在尝试将 newtonsoft dll 安装到全局程序集缓存。 In order to accomplish this do I have to install Newtonsoft to the server for instance its saved to C directory.为了做到这一点,我必须将 Newtonsoft 安装到服务器上,例如将其保存到 C 目录中。 Then install it to global assembly cache using gacutil.然后使用 gacutil 将其安装到全局程序集缓存。

 C:\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll
    
 gacutil /i Newtonsoft.Json.dll

In the Script Task C# code reference the dll like below?在脚本任务 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"));
}

You don't need to install it in the GAC if you use Reflection , you just need to make sure the DLL sits in the same path on the server as which you are referring to in your code如果您使用Reflection ,则不需要在 GAC 中安装它,您只需要确保 DLL 位于服务器上与您在代码中引用的路径相同的路径中

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM