Differences

This shows you the differences between the selected revisions of the page.

2015-06-24 2015-06-24
Adding information about assembly location redirection (tsaukpaetra) it's not a static constructor handler but assemblyresolve handler subscribed in static contructor + removing the example, the use is too minor, keeping a link only (martin)
Line 20: Line 20:
When deploying your SSIS package, WinSCP .NET assembly should be [[library_install#gac|installed to GAC]] to be accessible. When deploying your SSIS package, WinSCP .NET assembly should be [[library_install#gac|installed to GAC]] to be accessible.
-It is possible to redirect the assembly elsewhere, however the location must be accessible by the user that the package is running as, and a Static Constructor handler needs to be attached inside the script (See [[http://blogs.msdn.com/b/dbrowne/archive/2014/06/25/how-to-load-an-assembly-in-a-ssis-script-task-that-isn-t-in-the-gac.aspx|This MSDC blog article]] for more detailed information). 
-Some sample code (Add inside the class): +Alternatively, you can subscribe ''[[https://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve.aspx|AppDomain.AssemblyResolve]]'' event in a static constructor handler of the script task class to locate the assembly in an another location. For details, see article [[http://blogs.msdn.com/b/dbrowne/archive/2014/06/25/how-to-load-an-assembly-in-a-ssis-script-task-that-isn-t-in-the-gac.aspx|How to load an Assembly in a SSIS script task that isn't in the GAC]]. 
-··public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase +
-··{ +
-·····static ScriptMain() +
-·····+
-        AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); +
-········//The rest of your code +
-     } +
-     static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) +
-·····{ +
-·········if (args.Name.Contains("winscpnet.dll")) +
-·········{ +
-·············string path = @"c:\temp\"; +
-·············return System.Reflection.Assembly.LoadFile(System.IO.Path.Combine(path, "winscpnet.dll")); +
- ········} +
-         return null; +
-·····} +
-  }+
===== [[example]] Example C# Script Task Code ===== ===== [[example]] Example C# Script Task Code =====

Last modified: by martin