简体   繁体   中英

SSIS Script Task Fails with NewtonSoft.Json

I have a C# code embedded in a script task in SSIS , and I installed NewtonSoft.Json for some json processing. When I run the package, below error shows up:

Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.

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 component fails.

I am using Visual Studio 2017 (SSDT).

How to solve the issue permanently?

With SSIS, you can only reference assemblies installed on the GAC. Use gacutil, from Windows SDK to install the required assembly to the GAC

gacutil -I "[DriveLetter]:\[PathToBinDirectoryInVSProject]\gac.dll"

If GAC is not available, you can still use AssemblyResolve point to a custom folder.

        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;
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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