c# - 将 newtonsoft 安装到全局程序集缓存以用于 SSIS 脚本任务
问题描述
我正在使用 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"));
}
解决方案
如果您使用Reflection,则不需要在 GAC 中安装它,您只需要确保 DLL 位于服务器上与您在代码中引用的路径相同的路径中
C:\Newtonsoft.Json.12.0.3\lib\net45\
推荐阅读
- r - 有没有办法提取 coeftest() 函数的 $R^2$ ?
- react-native - LottieView 垂直中心在 IOS 上不起作用
- javascript - 使用 React 如何在有和没有地址栏和标签的情况下调整 Mobile Safari 高度
- c++ - C ++如何将char *保存到char *数组中[]
- deployment - 如何使用本地命令设置要在 ansible 任务中使用的多个变量
- javascript - 我在元素中添加了一个按钮,因为它们是在 html 中生成的,而不是给它们一个 onclick 处理程序但得到错误
- oracle - Oracle ODBC,64 位和 32 位,同名
- python - Bokeh 中的链接刷亮是否适用于折线图?
- c# - WPF WVVM:在哪里/如何创建全局错误消息和程序常量?
- c# - EmitIL - 使用 ref 参数调用方法