[英]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.