4
votes

I installed the dll to the GAC even updated the dll to install that into the GAC but I get this error:

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

App.config

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
         </dependentAssembly>
      </assemblyBinding>
   </runtime>
</configuration>

GAC location:

C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Newtonsoft.Json\v4.0_12.0.0.0__30ad4fe6b2a6aeed\Newtonsoft.Json.dll

I also copied the dll to the C:\Windows\System32 but when I try to add it as a reference from this location visual studios doesn't see it.

2
Are you running local or through the server / catalog? When run from server it needs to be in the server GAC. Another thing to check is 64bit vs 32bit runtime. - Joe C
@JoeC running this locally right now. - user3266638

2 Answers

4
votes

Try using the ResolveEventHandler delegate to load the .dll when an error is raised after it not being found. This can go directly above the Main() method.

static ScriptMain()
{
 AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
}
static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
    if (args.Name.ToUpper().Contains("NEWTONSOFT"))
    {
   string path = @"C:\DLL File Path\";
   return System.Reflection.Assembly.LoadFile(System.IO.Path.Combine(path, "Newtonsoft.Json.dll"));
    }
    return null;
}
public void Main()
{
    ...
1
votes

To fix this issue I added a new script task and opened nugget from inside it.

I installed the Microsoft.AspNet.WebApi.Client package and then from this package added the System.Net.Http and Newtonsoft.Json dlls to my GAC.

After that I referenced those new dlls from the location it added them into and this fixed the issue.

This will only work if you are able to install the dll into the GAC on the server/computer running your SSIS package.