SSIS脚本任务找不到Newtonsoft.Json

问题描述 投票:2回答:2

我将dll安装到GAC甚至更新了dll以将其安装到GAC中,但是我收到此错误:

“无法加载文件或程序集'Newtonsoft.Json,Version = 4.5.0.0,Culture = neutral,PublicKeyToken = 30ad4fe6b2a6aeed'或其中一个依赖项。系统找不到指定的文件。”:“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位置:

C:\ WINDOWS \ Microsoft.NET \装配\ GAC_MSIL \ Newtonsoft.Json \ v4.0_12.0.0.0__30ad4fe6b2a6aeed \ Newtonsoft.Json.dll

我还将dll复制到C:\ Windows \ System32但是当我尝试将它作为参考从这个位置添加时,visual studio看不到它。

c# ssis ssis-2012 gac
2个回答
1
投票

尝试使用ResolveEventHandler委托加载.dll后,如果在找不到错误后引发错误。这可以直接在Main()方法之上。

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
投票

为了解决这个问题,我添加了一个新的脚本任务,并从里面打开了一个块。

我安装了Microsoft.AspNet.WebApi.Client包,然后从这个包中添加了System.Net.Http和Newtonsoft.Json dll到我的GAC。

之后,我从它添加到的位置引用了这些新dll,这解决了这个问题。

只有在能够在运行SSIS包的服务器/计算机上将dll安装到GAC中时,这才有效。

© www.soinside.com 2019 - 2024. All rights reserved.