0

Getting a little frustrated here. I am trying to use the newtonsoft.json library in a c# script task in SSIS. I open the solution, I went to references and installed it via "manage NuGet packages".

When I install it, it's all well and good and I can start writing code and I get no errors. However, as soon as I save the solution and exit out of vs back to ssis, if I open it again, the reference now has a warning icon and says "The referenced component 'Newtonsoft.Json' could not be found" and all my code is underlined red.

Any ideas on how to fix this??

Not sure if it's worth noting but I didn't download/save any .dll files or install anything other than just in the "manage nuget packages" console

This is what my packages.config lists:

<?xml version="1.0" encoding="utf-8"?>
   <packages>
   <package id="Newtonsoft.Json" version="12.0.1" targetFramework="net45" />
   </packages>

Also not sure if this is important but in the packages.config, the first " < packages > " is underlined blue and states "the "packages" element is not declared."

user3494110
  • 417
  • 2
  • 9
  • 25
  • Have you included the assembly as a reference along with adding a using statement in the script task? Also, do you build, save, and close VSTA and then click OK on the script task editor when you're done? Note: If you click cancel, your changes will not be saved in the package. – J Weezy Feb 28 '19 at 18:42
  • Thank you for the response. Yes I have done everything noted. Unfortunately the problem persists. – user3494110 Feb 28 '19 at 18:45
  • 3
    To the best of my knowledge, SSIS Script task/component don't support the whole nuget workflow. They need to have their DLLs in the global assembly cache (GAC) to work – billinkc Feb 28 '19 at 18:49
  • @bilinkc So, with this particular reference, how do you get the .dll for it? For instance when I try to install it, it comes in a .nupkg. – user3494110 Feb 28 '19 at 18:53
  • It used to be on codeplex but I don't nothing about this library beyond it's the defacto JSON thing https://stackoverflow.com/questions/11611165/add-third-party-dll-reference-in-ssis-script-component/11614009#11614009 – billinkc Feb 28 '19 at 19:08
  • I typically work on govt contracts that can't use outside tools like Nuget. I find the JavaScriptSerializer class (add reference to System.Web.Extensions works just fine – KeithL Feb 28 '19 at 20:32

1 Answers1

0

I've done this kind of problem before. What I did is I imported the Newtonsoft.Json dll reference manually inside of Script Task from my SSIS solution.

After that you will be needing to register its dll to GAC(Global Assembly Cache) to be able to load or use properly the functions once the solution has been run.

  public System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
    {
        if (args.Name.Contains("Newtonsoft.Json"))
        {
            string path = @"D:\Projects\FortiAnalyzer\FortiAnalyzer\FortiAnalyzer\bin\portable-net45+win8+wp8+wpa81\Newtonsoft.Json.dll";
            return System.Reflection.Assembly.LoadFile(@path);
        }
        return null;
    }

then in your Main you need to use this code to run the loading of dll in GAC

        //Register Reference 'Newtonsoft.Json' to GAC initially every run of this Script
        AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
visss
  • 1