VS - How to fix "Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0"

Jocelyn Kwong 0 Reputation points
2025-01-31T11:58:33.4366667+00:00

Hi,

I have created a new SSIS project in Visual Studio, and there is a Script Task built in the SSIS package. This Script Task is used get a bearer token from an API website, this C# script run successfully in C# Console.

When I run the Script Task component in the SSIS package, I always get the error message (see below).

I could see the 'Newtonsoft.Json.13.0.1' has installed in the script package, so I don't know what's wrong on my laptop setting.

How could I resolve this problem?

Here below is the Environment Information.

Version of Visual Studio: Microsoft Visual Studio Professional 2019 (Version 16.11.42)

Version of NET: Microsoft .NET Framework Version 4.8.09.37

Version of Target SQL Server: Microsoft SQL Server 2016

Inside the Script Task Editor (VSTA), I have installed the following NuGet packages.

a) Install Microsoft.AspNet.WebApi.Client 6.0.0, included

  • Newtonsoft.Json.13.0.1
  • Newtonsoft.Json.Bson.1.0.2
  • System.Buffers.4.5.1
  • System.Runtime.CompilerServices.Unsafe.4.5.3
  • System.Memory.4.5.5
  • System.Threading.Tasks.Extensions.4.5.4
  • Microsoft.AspNet.WebApi.Client.6.0.0

b) Install the Microsoft.CSharp 4.7.0, included

  • Microsoft.CSharp.4.7.0

Error Message: -

Error: 0x0 at Get Bearer Token, Script Task: Error: Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.

Many thanks.

Best regards,

Jocelyn

SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,649 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. ZoeHui-MSFT 40,901 Reputation points
    2025-02-03T03:15:26.75+00:00

    Hi @Jocelyn Kwong,

    Install the assembly

    Open a command prompt in administrator mode. This may prompt the UAC dialog to pop and you might need to use admin credentials depending on your security set up.

    Installation to the GAC is straight-forward after that.

    "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe"
    

    /if signals Install and Force a re-install even if the assembly already exists.

    If I wanted to install the newtonsoft dll from above, that syntax would be

    "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe" /if "C:\Users\bfellows\AppData\Local\Temp\vsta\SSIS_ST140\VstatIBdQdlmHEa__RFeT36Nd9A\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll"

    Kindly check below links to see if it is helpful.

    https://stackoverflow.com/questions/65632495/could-not-load-file-or-assembly-ssis-script-task

    https://github.com/JamesNK/Newtonsoft.Json/issues/2574

    Regards,

    Zoe Hui


    If the answer is helpful, please click "Accept Answer" and upvote it.


  2. Michael Taylor 56,956 Reputation points
    2025-02-05T22:25:10.32+00:00

    That isn't how SSIS works at runtime, unfortunately. You're used to having all your code and dependencies dropped into an output directory and then you can run your app. Because it can find the dependencies, from NuGet generally, it works. But SSIS packages don't work that way.

    In order for SSIS to run your script task it has to load it into an isolated shell. That shell runs in the context of DtsExec (or DtsHost). Your NuGet packages aren't available to it and cannot be used.

    The workaround is to ensure the dependencies are in the GAC. When the runtime tries to find an assembly it'll look in the GAC if the assembly is strongly signed. The GAC is shared across the machine. Only assemblies in the GAC can be referenced by your script task. Therefore you can only take a dependency on packages that are signed AND you have installed the assemblies in the GAC. If an assembly isn't signed then you cannot use it in a script task.

    To install an assembly in the GAC you need to follow the steps given by @ZoeHui-MSFT . You have to do this for each assembly you rely on, and its dependencies as well. Furthermore the GAC is versioned so every time you update your dependencies you have to also remember to install the newer version in the GAC as well. Otherwise you'll get a runtime error.

    Note that there are 2 GACs - x86 and x64. I suspect your SSIS package is configured to use the x64 SSIS runtime (check your SSIS package properties). Therefore you need to follow the steps given for installing into the GAC from a command prompt/powershell session that is running as x64. Otherwise you'll continue to receive the error. If you're using x86 runtime then ensure you're using the x86 prompt/session instead.

    In general you should avoid taking any dependencies on assemblies outside the NET Framework library when creating SSIS tasks. They require a lot more effort and an installation step. Most functionality can be done using framework assemblies even if the technology is older. For example you may be able to use the DataContractSerializer type built into the framework to read your JSON data. It isn't ideal but requires no extra deployment steps.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.