[英]SSIS how to execute dll in script-task (SharePoint function not found)
I can not use a specific DLL in SSIS script-task. 我不能在SSIS脚本任务中使用特定的DLL。 In c# console-project anything is fine.
在c#console-project中,一切都很好。 SSIS throws the error:
SSIS引发错误:
Error: The Type "Microsoft.SharePoint.Client.ClientRuntimeContext" in assembly "Microsoft.SharePoint.Client, Version=14.0.0.0, Culture=neutral PublicKeyToken=...." could not be loaded.
错误:无法加载程序集“ Microsoft.SharePoint.Client,版本= 14.0.0.0,区域性=中性PublicKeyToken = ....”中的类型“ Microsoft.SharePoint.Client.ClientRuntimeContext”。
I am running Visual Studio 2017 with Datatools. 我正在使用Datatools运行Visual Studio 2017。 I got the libraries from NuGet-paket-manager and saved them local on C:/
我从NuGet-paket-manager获得了库,并将它们保存在本地C:/
My console-project is .NET 4.6 and i ve setted the SSIS project also to .NET 4.6. 我的控制台项目是.NET 4.6,并且我还将SSIS项目也设置为.NET 4.6。 In both cases I added the libraries with rightclick on References > Add > Search from computer
在这两种情况下,我都通过右键单击“引用”>“添加”>“从计算机搜索”来添加库
I just tested a console-project without any problems: 我刚刚测试了一个控制台项目,没有任何问题:
static void Main(string[] args)
{
using (ClientContext clientContext = new ClientContext("urltomysite.com"))
{
}
Console.WriteLine("finished");
}
And this is the code in SSIS (it is similar... Just uses the object ClientContext: 这是SSIS中的代码(类似...仅使用对象ClientContext:
public void Main()
{
//Loading assemblies extra
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve2);
try
{
//Testing the assembly method
Class1.TESTIT();
}
catch (Exception ex)
{
Dts.Events.FireError(0, "Error", ex.Message, null, 0);
Dts.TaskResult = (int)ScriptResults.Failure;
}
}
static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
return System.Reflection.Assembly.LoadFile(System.IO.Path.Combine("C:/", "Microsoft.SharePoint.Client.dll"));
}
static System.Reflection.Assembly CurrentDomain_AssemblyResolve2(object sender, ResolveEventArgs args)
{
return System.Reflection.Assembly.LoadFile(System.IO.Path.Combine("C:/", "Microsoft.SharePoint.Client.Runtime.dll"));
}
class Class1
{
public static void TESTIT()
{
using (ClientContext clientContext = new ClientContext("urltomysite.com"))
{
}
}
}
I have finally found the mistake... 我终于找到了错误...
I had to load first 我必须先加载
And afterwards i had to load the other library 然后,我不得不加载另一个库
So in Main I switched the library-loading: 所以在Main我切换了库加载:
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve2);
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.