Re: script task dll reference w/o being in gac
Jason Gerard
Here is a script task that uses the Assembly object from the System.Reflection namespace. It loads a plane assembly that has not been strong named or put in the GAC and calls a method on it passing it a single String as a parameter. I tested this code with real values on one of my assemblies first. The names have been changed to protect the innocent. ;-)
It's a lot of code however.
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.Reflection
Imports System.Windows.Forms
Public Class ScriptMain
Public Sub Main()
'
' Add your code here
'
Dim myAssembly As Assembly
'load the assembly
myAssembly = Assembly.LoadFrom("C:\Path\To\The\Assembly.dll")
'get a reference to the type
Dim t As Type = myAssembly.GetType("Namespace.Name.Of.Class")
' create an instance of the object
Dim obj As Object = Activator.CreateInstance(t, True)
' create an array Type objects for the parameters
' This method only accepts one parameter that is a string
Dim argtype(0) As Type
argtype(0) = "".GetType()
'get the method
Dim mi As MethodInfo = t.GetMethod("MethodName", argtype)
'similar to above. No specifying an array of the
' parameter values
Dim params(0) As Object
params(0) = "my parameter value"
'invoke the method and get the results
Dim results As Object = mi.Invoke(obj, params)
' Display the results as a string
MessageBox.Show(results.ToString())
Dts.TaskResult = Dts.Results.Success
End Sub
End Class