Public Function GetCustomScrubberDetails(ByVal iImportDefaultSeqNo As Integer) As ICustomScrubs Dim objDALImport As New CommonParsingData Dim dsScrubberAssembly As New DataSet Dim hdlScrubber As System.Runtime.Remoting.ObjectHandle Dim ifCustomScrubs As ICustomScrubs Try Dim sLoc As String Dim sPath As String Dim sDll As String Dim sClass As String Dim asm As Reflection.Assembly dsScrubberAssembly = objDALImport.RtnCustomScrubberDetails(iImportDefaultSeqNo) If dsScrubberAssembly.Tables.Count > 1 Then If dsScrubberAssembly.Tables("CustomScrubbers").Rows.Count > 0 Then Dim drAssembly As DataRow drAssembly = dsScrubberAssembly.Tables("CustomScrubbers").Rows(0) sDll = drAssembly("Scrubber_Assembly_Name").ToString.Trim() sClass = drAssembly("Class_Name").ToString.ToUpper.Trim() asm = Reflection.Assembly.GetExecutingAssembly() sLoc = asm.Location sPath = Path.Combine(Path.GetPathRoot(sLoc), Path.GetDirectoryName(sLoc)) sDll = Path.Combine(sPath, sDll) ' Note: The type parameter (sClass) of Activator.CreateInstanceFrom is CASE SENSITIVE!!! hdlScrubber = Activator.CreateInstanceFrom(sDll, sClass) ifCustomScrubs = DirectCast(hdlScrubber.Unwrap(), ICustomScrubs) End If End If If objHewException.CheckForErrorTable(dsScrubberAssembly) = False Then dsScrubberAssembly.Tables.Add(objHewException.CreateErrorTable()) End If Catch objEx As Exception If objHewException.CheckForErrorTable(dsScrubberAssembly) = True Then dsScrubberAssembly.Tables.Remove("ErrorTable") End If dtError = objHewException.AddHewException(objEx, System.Reflection.Assembly.GetExecutingAssembly) dsScrubberAssembly.Tables.Add(dtError) Finally GetCustomScrubberDetails = ifCustomScrubs dsScrubberAssembly = Nothing objDALClaimImport = Nothing End Try End FunctionThis was some of the first dotnet code I wrote (the guys who developed the system could not figure out how to implement the factory pattern). I would do things a little differently if I did it again, but it works.
hdlScrubber = Activator.CreateInstanceFrom(sDll, sClass) ifCustomScrubs = DirectCast(hdlScrubber.Unwrap(), ICustomScrubs)Later on in code we only need to check if ifCustomScrubs is NOT NULL. Since it is an interface, we know what methods are implemented.