Access .NET assembly through SSIS (Script Component)






2.50/5 (8 votes)
Oct 8, 2006
1 min read

58562
Here is some cool stuff to call .NET assembly from SSIS
Introduction
Hi All,
Here is some cool stuff to call .NET assembly from Script Component of SSIS.
Remember whenever we use “Script Component” while developing SSIS application, by default we get list of assembly on click of “Add Reference” from default path …Microsoft.NET\Framework\v2.0.50727, as shown below,
Now question is how to call any business logic (Included in .NET assembly) from Script Component…?
I would say put physically that assembly (Which needs to be referenced) at …Microsoft.NET\Framework\v2.0.50727. But I believe this would be just a work around not a proper solution.
What follows is another approach to accustom described functionality,
1. Import “System.Reflection” assembly in Script Component
2. Add assembly (Which need to be referenced) in GAC
3. Write following code to call external assembly from your own Script Component of SSIS.
//Define variable of type [Assembly]
Dim targetAssembly As [Assembly] = Nothing
//Load assembly named “CallBySSIS” from GAC into defined variable
targetAssembly = [Assembly].LoadWithPartialName("CallBySSIS")
//Define variable which used to hold “Type” object
Dim targetType As Type
//Get specific class from assembly here “clsTest”
targetType = targetAssembly.GetType("CallBySSIS.clsTest")
//Define variable of type Object
Dim objClsTest As Object
//Get instance of “clsTest” into defined variable
objClsTest = targetType.InvokeMember("clsTest", BindingFlags.CreateInstance, Nothing, Nothing, Nothing)
//Now you are free bird to call function of class “clsTest” named //“writeToFile(String strMessage)”
objClsTest.writeToFile("Colour Dataflow : " + ex.Message)
4. Add “option Strict Off” on the top of script component; else compile time error for casting will occur.
I hope this article will save SSIS developers life, since it shows path how to use complex logic written previously.