SSIS脚本任务找不到Newtonsoft.Json

use*_*638 4 c# ssis gac ssis-2012

我将 dll 安装到了 GAC 中,甚至更新了 dll 以将其安装到了 GAC 中,但出现以下错误:

“无法加载文件或程序集“Newtonsoft.Json,版本=4.5.0.0,Culture=neutral,PublicKeyToken=30ad4fe6b2a6aeed”或其依赖项之一。系统找不到指定的文件。”:“Newtonsoft.Json,版本=4.5 .0.0,文化=中立,PublicKeyToken=30ad4fe6b2a6aeed”}

应用程序配置

<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>
Run Code Online (Sandbox Code Playgroud)

广汽集团地点:

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

我还将 dll 复制到了 C:\Windows\System32,但是当我尝试从该位置将其添加为引用时,视觉工作室看不到它。

use*_*l89 9

ResolveEventHandler当未找到 .dll 后引发错误时,尝试使用委托加载 .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()
{
    ...
Run Code Online (Sandbox Code Playgroud)