SSIS how to execute dll in script-task (SharePoint function not found)

Viewed 1107

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

1 Answers

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);
Related