1

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?

Jozott
  • 2,367
  • 2
  • 14
  • 28
khidir sanosi
  • 161
  • 11

2 Answers2

2

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;
        }
vhoang
  • 1,349
  • 1
  • 8
  • 9
1

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"
Oscar
  • 13,594
  • 8
  • 47
  • 75