I came across a requirement to access third party dlls in SSIS Package. which is fairly easy. the tricky part is where to deploy those third party dlls. In almost all the blogs that i came across while search the solution, I was told to deploy them in GAC. Which I don't think ideal solution in all the environment. Let me move to solution directly.
- Create a parameter that hold the directory which has all the third party files.
- Pass the variable name in Script
- In your Script, add following line.
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
best place to add this is in PreExecute. This will call the attached event handler whenever it will try to load a third party dll.
And add the related event handler in the same class.
Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
if(args.Name.IndexOf("MyCustomDll1.dll")>0)
return Assembly.LoadFile(Path.Combine(Variables.SupportDirectory,"MyCustomDll1.dll"));
else if(args.Name.IndexOf("MyCustomDll2.dll")>0)
return Assembly.LoadFile(Path.Combine(Variables.SupportDirectory,"MyCustomDll2.dll"));
else
return Assembly.GetExecutingAssembly();
}
It is important to return the executing assembly in else.
-That's it. now it will load all the dll from the folder that you have specified. You just need to make sure that the files exist in that folder.
Thanks,
HP
- Create a parameter that hold the directory which has all the third party files.
- Pass the variable name in Script
- In your Script, add following line.
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
best place to add this is in PreExecute. This will call the attached event handler whenever it will try to load a third party dll.
And add the related event handler in the same class.
Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
if(args.Name.IndexOf("MyCustomDll1.dll")>0)
return Assembly.LoadFile(Path.Combine(Variables.SupportDirectory,"MyCustomDll1.dll"));
else if(args.Name.IndexOf("MyCustomDll2.dll")>0)
return Assembly.LoadFile(Path.Combine(Variables.SupportDirectory,"MyCustomDll2.dll"));
else
return Assembly.GetExecutingAssembly();
}
It is important to return the executing assembly in else.
-That's it. now it will load all the dll from the folder that you have specified. You just need to make sure that the files exist in that folder.
Thanks,
HP