SSIS如何在脚本任务中执行dll(未找到SharePoint功能)

时间:2019-06-26 14:37:49

标签: c# sharepoint dll ssis script-task

我不能在SSIS脚本任务中使用特定的DLL。在c#console-project中,一切都很好。 SSIS引发错误:

  

错误:程序集“ Microsoft.SharePoint.Client,版本= 14.0.0.0,区域性=中性PublicKeyToken = ....”中的类型“ Microsoft.SharePoint.Client.ClientRuntimeContext”无法加载。

我正在使用Datatools运行Visual Studio 2017。我从NuGet-paket-manager获得了这些库,并将它们保存在本地C:/

  • Microsoft.SharePoint.Client,版本14.0.0.0,运行时版本v2.0.50727
  • Microsoft.SharePoint.Client.Runtime,版本15.0.0.0,运行时版本v4.0.30319

我的控制台项目是.NET 4.6,并且我还将SSIS项目也设置为.NET 4.6。在这两种情况下,我都通过右键单击“引用”>“添加”>“从计算机搜索”来添加库。

我刚刚测试了一个控制台项目,没有任何问题:


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"))
        {
        }
    }
}

1 个答案:

答案 0 :(得分:1)

我终于找到了错误...

我必须先加载

  • Microsoft.SharePoint.Client.Runtime.dll

然后我必须加载另一个库

  • Microsoft.SharePoint.Client.dll

因此在Main中,我切换了库加载:

a, a:visited