SSIS 如何在脚本任务中执行 dll(未找到 SharePoint 函数)
SSIS how to execute dll in script-task (SharePoint function not found)
我无法在 SSIS 脚本任务中使用特定的 DLL。在 c# 控制台项目中,一切都很好。 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.
我 运行 Visual Studio 2017 年使用 Datatools。我从 NuGet-paket-manager 获取库并将它们保存在本地 C:/
- Microsoft.SharePoint.Client,版本 14.0.0.0,运行时版本 v2.0.50727
- Microsoft.SharePoint.Client.运行时,版本 15.0.0.0,运行时版本 v4.0.30319
我的控制台项目是 .NET 4.6,我也将 SSIS 项目设置为 .NET 4.6。在这两种情况下,我都通过右键单击 References > Add > Search from computer
添加了库
我刚刚测试了一个控制台项目没有任何问题:
static void Main(string[] args)
{
using (ClientContext clientContext = new ClientContext("urltomysite.com"))
{
}
Console.WriteLine("finished");
}
这是 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"))
{
}
}
}
终于找到错误了...
我必须先加载
- Microsoft.SharePoint.Client.Runtime.dll
然后我不得不加载另一个库
- Microsoft.SharePoint.Client.dll
所以在 Main 中我切换了 library-loading:
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve2);
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
我无法在 SSIS 脚本任务中使用特定的 DLL。在 c# 控制台项目中,一切都很好。 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.
我 运行 Visual Studio 2017 年使用 Datatools。我从 NuGet-paket-manager 获取库并将它们保存在本地 C:/
- Microsoft.SharePoint.Client,版本 14.0.0.0,运行时版本 v2.0.50727
- Microsoft.SharePoint.Client.运行时,版本 15.0.0.0,运行时版本 v4.0.30319
我的控制台项目是 .NET 4.6,我也将 SSIS 项目设置为 .NET 4.6。在这两种情况下,我都通过右键单击 References > Add > Search from computer
添加了库我刚刚测试了一个控制台项目没有任何问题:
static void Main(string[] args)
{
using (ClientContext clientContext = new ClientContext("urltomysite.com"))
{
}
Console.WriteLine("finished");
}
这是 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"))
{
}
}
}
终于找到错误了...
我必须先加载
- Microsoft.SharePoint.Client.Runtime.dll
然后我不得不加载另一个库
- Microsoft.SharePoint.Client.dll
所以在 Main 中我切换了 library-loading:
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve2);
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);