【问题标题】:SSIS how to execute dll in script-task (SharePoint function not found)SSIS如何在脚本任务中执行dll(找不到SharePoint函数)
【发布时间】:2019-06-26 14:37:49
【问题描述】:

我不能在 SSIS 脚本任务中使用特定的 DLL。在 c# 控制台项目中,一切都很好。 SSIS 抛出错误:

错误:无法加载程序集“Microsoft.SharePoint.Client, Version=14.0.0.0, Culture=neutral 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"))
        {
        }
    }
}

【问题讨论】:

  • 我认为从错误消息中您正在使用 SQL Server 2014 和 Net Library 4.0。 v4.0.30319 版本是 Net Library 4.0 作为目标。根据过去的经验,SQL 库必须与机器上安装的版本相匹配。 NuGet 可能是用不同的版本编译的。所以我怀疑你需要在你的机器上重新编译 NuGet。所以尝试构建:清洁解决方案和重新编译。我会复制 NUGET Bin 文件夹,以防文件被手动放入文件夹中。
  • 尝试使用以下代码return System.Reflection.Assembly.LoadFile(System.IO.Path.Combine(@"C:\", "Microsoft.SharePoint.Client.dll"));并确保dll位于C:
  • 您的 SharePoint 服务器版本?
  • @jdwengIm 我打开了 VSTA,打开了 PM 控制台并输入了 Get-Project –All | Add-BindingRedirect。它只是向我展示了“Microsoft.SharePoint.Client.Runtime”包之一。我清理、重建并保存了解决方案。在下一次运行 ssis-package 时,它​​再次失败。我已将 SSIS-proejct 设置为 SQL-Server 2016:同样的问题。您还有其他建议吗?
  • @Hadi 谢谢,但这没有用。

标签: c# sharepoint dll ssis script-task


【解决方案1】:

我终于找到了错误……

我必须先加载

  • Microsoft.SharePoint.Client.Runtime.dll

然后我不得不加载另一个库

  • Microsoft.SharePoint.Client.dll

所以在 Main 我切换了库加载:

AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve2);
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-01
    相关资源
    最近更新 更多