[英]SSIS Script Task Fails with NewtonSoft.Json
我在SSIS
的脚本任务中嵌入了一个C#
代码,并且我安装了NewtonSoft.Json
用于一些 Z4466DEEC716ECDF25DCA 处理。 当我运行 package 时,出现以下错误:
无法加载文件或程序集“Newtonsoft.Json,版本=12.0.0.0,文化=中性,PublicKeyToken=30ad4fe6b2a6aeed”或其依赖项之一。 该系统找不到指定的文件。
Despite trying all solutions and recommendations (uninstall & re-install the package, both from NuGet manager and through console, or adding the reference manually, etc.. ), whenever I run the SSIS package I still get the same error and the script task组件失败。
我正在使用 Visual Studio 2017 (SSDT)。
如何永久解决问题?
使用 SSIS,您只能引用安装在 GAC 上的程序集。 使用 gacutil,从 Windows SDK 安装所需的程序集到 GAC
gacutil -I "[DriveLetter]:\[PathToBinDirectoryInVSProject]\gac.dll"
如果 GAC 不可用,您仍然可以使用AssemblyResolve指向自定义文件夹。
static ScriptMain()
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
}
static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
string name = new System.Reflection.AssemblyName(args.Name).Name;
string library_path = Environment.GetEnvironmentVariable("LIBRARY_PATH", EnvironmentVariableTarget.Process);
string dll = (library_path + @"\" + name + ".dll").Replace(@"\\", @"\");
if (File.Exists(dll))
{
return System.Reflection.Assembly.LoadFile(dll);
}
return null;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.