1

I am trying to load a dll in a SSIS project that ins't in a GAC. I followed the following code from here

the code:

[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
     static ScriptMain()
     {
         AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
     }
     static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
     {
         if (args.Name.Contains("ssisHelper"))
         {
             string path = @"c:\temp\";
             return System.Reflection.Assembly.LoadFile(System.IO.Path.Combine(path, "ssisHelper.dll"));
         }
         return null;
     }
}

This enabled the loading of the dll but it keep giving me the following error because Entity Framework was referenced inside the dll.

Could not load file or assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.

So I tried to set the Working directory of dll with no success because dll's don't have an entry point. So I got the idea to put the file in a console application from here. I built an .exe and changed it to a .dll. Now in theory I have an entry point where I could set the working directory.

System.Environment.CurrentDirectory = @"PathToDll";

Yet I still get the same error. Does any one know of a solution?

Hadi
  • 36,233
  • 13
  • 65
  • 124
Dblock247
  • 6,167
  • 10
  • 44
  • 66
  • That code you've got there for telling SSIS that anything with "ssisHelper" in the name should be loaded from C:\Temp\? It should work just as well for Entity Framework, or any other assembly you'd wanted to load. – Jeroen Mostert Oct 21 '16 at 20:01
  • @JeroenMostert How do I change it so I can load Multiple assembly's? Do you have an example. – Dblock247 Oct 21 '16 at 20:02

1 Answers1

1

Try to add an else if clause for each Assembly name:

static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            if (args.Name.Contains("ssisHelper"))
            {
            string path = @"c:\temp\";
            return System.Reflection.Assembly.LoadFile(System.IO.Path.Combine(path, "ssisHelper.dll"));

        }
        else if (args.Name.Contains("xxx"))
             {
            string path = @"c:\temp\";
            return System.Reflection.Assembly.LoadFile(System.IO.Path.Combine(path, "xxx.dll"));


        };    return null;
Hadi
  • 36,233
  • 13
  • 65
  • 124
  • Thanks I actually did stumbled over this on Friday. But this is correct. Do you have any Idea how to connect to the config file from the dll. Im getting a connection string error. I also need other configuration settings to be accessible. – Dblock247 Oct 24 '16 at 11:45
  • Which configuration file? Tip : dont forget to add provider to the connectionstring – Hadi Oct 24 '16 at 12:00
  • SSIS is load a dll that that connects to a database. The dll file uses a config file with the connection string in it. However when its loaded into SSIS its not loading that config file so I get a connection string error. – Dblock247 Oct 24 '16 at 13:29
  • Is this dll made by you? Do you have source code? If yes you must modify the function to pass connectionstring as a parameter. If not i dont think you can modify dll from ssis so it recommended to update your question and write that problem. Or mark it as answered and ask a new question. So your question will be visible to other users. – Hadi Oct 24 '16 at 13:57