简体   繁体   中英

SSIS C# script task Newtonsoft.json reference keeps giving error“ The Referenced component newtonsoft.json cannot be found”

Getting a little frustrated here. I am trying to use the newtonsoft.json library in ac# 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."

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

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