简体   繁体   English

在SSIS脚本组件中添加第三方DLL参考

[英]Add third party dll reference in ssis script component

I have added third party reference (Json newtonsoft) dll in my script component (using edit script option), but when i run the package, I am getting an error 我在脚本组件中添加了第三方参考(Json newtonsoft)dll(使用“编辑脚本”选项),但是当我运行该软件包时,出现了错误

Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. 无法加载文件或程序集“ Newtonsoft.Json,版本= 4.5.0.0,区域性=中性,PublicKeyToken = 30ad4fe6b2a6aeed”或其依赖项之一。 The system cannot find the file specified. 该系统找不到指定的文件。

Any suggestions? 有什么建议么?

I will not be able to add the dll in GAC. 我将无法在GAC中添加dll。

I am using SQL Server 2008. 我正在使用SQL Server 2008。

By "Running," I assume running from agent/command-line is failing? 通过“正在运行”,我假设从代理/命令行运行失败? It should work from within BIDS/SSDT. 它应该在BIDS / SSDT中运行。 The short answer is the DLL must be registered with the GAC or you can download the source code and add that project into the script task and then reference said project. 简短的答案是DLL必须在GAC中注册,或者您可以下载源代码并将该项目添加到脚本任务中,然后引用该项目。

Looking at the project, it should be a strongly signed DLL (based on presences of Dynamic.snk ) and thus capable of being added to the GAC. 查看该项目,它应该是一个经过强签名的DLL(基于Dynamic.snk的存在),因此能够将其添加到GAC中。 Oh, but you state you will not be able to add it into the GAC, implying it's a permission not a capability issue. 哦,但是您声明您将无法将其添加到GAC中,这意味着这是权限而不是功能问题。

If that's the case, either compile the project in with the source or surround it with a web service wrapper and then reference the service. 如果是这种情况,请使用源代码编译项目,或者使用Web服务包装程序将其包围,然后引用服务。

I also saw this answer, seems you can try loading the references dynamically. 我也看到了这个答案,似乎可以尝试动态加载引用。

You can using Reflection to load dll at runtime from file system without needing to install in GAC . 您可以使用Reflection在运行时从文件系统加载dll,而无需在GAC中安装。 This is helpful if permission to install in GAC is not availaible . 如果没有在GAC中安装的许可,这将很有帮助。

//Add a Static Constructor which is guaranteed to be called exactly once
// “before the first instance is created or any static members are referenced.”, 
// so therefore before the dependent assemblies are loaded.

 static ScriptMain()
 {
    AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
 }

 //Provide path to dll stored in folder on file system
 static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
 {

     string path = @"D:\DLL\";
     return System.Reflection.Assembly.LoadFile(System.IO.Path.Combine(path, "Newtonsoft.dll"));

  }

Ofcourse you need to also Add Reference to dll in script task . 当然,您还需要在脚本任务中添加对dll的引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM