-
-
Save LSTANCZYK/9f8709e1fb318e36f87054146a10a045 to your computer and use it in GitHub Desktop.
SSIS Load Dll without GAC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ScriptMain() | |
{ | |
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); | |
} | |
public Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) | |
{ | |
Assembly assembly = null; | |
try | |
{ | |
assembly = LoadAssembly(args, assembly); | |
} | |
catch (Exception exception) | |
{ | |
Dts.Log(exception.ToString(), 0, new byte[0]); | |
throw; | |
} | |
Dts.Log("Exiting CurrentDomain_AssemblyResolve", 0, new byte[0]); | |
return assembly; | |
} | |
private Assembly LoadAssembly(ResolveEventArgs args, Assembly assembly) | |
{ | |
Dts.Log(string.Format("Entering CurrentDomain_AssemblyResolve with args.Name [{0}]", args.Name), 0, new byte[0]); | |
String _Common_DLLs = Dts.Variables["User::DLLs_Path_Common"].Value.ToString(); | |
var dllName = string.Format("{0}.dll", args.Name.Split(',')[0]); | |
Dts.Log("DLL Name is " + dllName, 0, new byte[0]); | |
var dllFilename = Path.Combine(_Common_DLLs, dllName); | |
if (File.Exists(dllFilename)) | |
{ | |
Dts.Log(string.Format("The file [{0}] was found and that assembly will be loaded.", dllFilename), 0, new byte[0]); | |
assembly = Assembly.LoadFile(dllFilename); | |
} | |
else | |
{ | |
Dts.Log(string.Format("Couldn't find the file [{0}].", dllFilename), 0, new byte[0]); | |
} | |
return assembly; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment