5

I can not use a specific DLL in SSIS script-task. In c# console-project anything is fine. SSIS throws the error:

Error: The Type "Microsoft.SharePoint.Client.ClientRuntimeContext" in assembly "Microsoft.SharePoint.Client, Version=14.0.0.0, Culture=neutral PublicKeyToken=...." could not be loaded.

I am running Visual Studio 2017 with Datatools. I got the libraries from NuGet-paket-manager and saved them local on C:/

  • Microsoft.SharePoint.Client, Version 14.0.0.0, Runtime-Version v2.0.50727
  • Microsoft.SharePoint.Client.Runtime, Version 15.0.0.0, Runtime-Version v4.0.30319

My console-project is .NET 4.6 and i ve setted the SSIS project also to .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:


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 think from the error message you are using SQL Server 2014 and Net Library 4.0. The version v4.0.30319 is Net Library 4.0 as the target. From past experience the SQL Library must match the version installed on the machine. The NuGet is probably compiled with a different version. So I suspect you need to recompile the NuGet on your machine. So try a Build : Clean Solution and the Recompile. I would make a copy of the NUGET Bin folder incase files were manually put into the folder. – jdweng Jun 26 '19 at 15:41
  • Try using the following code `return System.Reflection.Assembly.LoadFile(System.IO.Path.Combine(@"C:\", "Microsoft.SharePoint.Client.dll"));` and make sure that the dll is located on `C:` – Hadi Jun 26 '19 at 18:52
  • Your version SharePoint server? – Mikhail Zhuikov Jun 27 '19 at 06:55
  • @jdwengIm I opened the VSTA, opened the PM-console and typed `Get-Project –All | Add-BindingRedirect`. It just shows me one of the package 'Microsoft.SharePoint.Client.Runtime'. I cleaned, rebuild and saved the solution. On next run of the ssis-package, it fails again. I have set the SSIS-proejct to SQL-Server 2016: same problem. Do you have any other tips? –  Jun 27 '19 at 13:15
  • @Hadi Thank you but this did not work. –  Jun 27 '19 at 13:15
  • @Fox Sorry but is this important? The console-project works fine. I don't know it, sorry. –  Jun 27 '19 at 13:17

1 Answers1

2

I have finally found the mistake...

I had to load first

  • Microsoft.SharePoint.Client.Runtime.dll

And afterwards i had to load the other library

  • Microsoft.SharePoint.Client.dll

So in Main I switched the library-loading:

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