IMPORTANT:
this is not a Support Forum! Experienced users might answer from time to time questions posted here. If you need a professional and reliable answer, or if you want to report a bug, please contact Altova Support instead.

Profile: DCJ
About
User Name: DCJ
Forum Rank: Newbie
Real Name:
Location South Africa
Occupation:
Interests:
Gender: None Specified
Statistics
Joined: Wednesday, February 1, 2012
Last Visit: Thursday, February 2, 2012 10:24:31 AM
Number of Posts: 2
[0.01% of all post / 0.00 posts per day]
Avatar
Last 10 Posts
Topic: Loading Mapforce generated dll at runtime using reflection/latebinding
Posted: Thursday, February 2, 2012 10:23:55 AM
Hi all, let me start of by saying that I am still a comparative .Net noob, so please be nice :).

I am trying to make use of a combination of late binding and reflection to load a dll that has been created by editing the output type of a Mapforce auto generated C# project to a class library. After generating the C# code I open up the generated solution and create a function RunDoc(Altova.IO.DocumentInput input2Source, Altova.IO.DocumentOutput output2Target) , which is essentially a copied version of the overloaded Run(Altova.IO.Input input2Source, Altova.IO.Output output2Target) with its input parameters changed to DocumentInput and DocumentOutput.

I then load the dll using reflection and create an instance of it using a directcast as below:

Code:
'Get the index of the assembly from a hash table
            Dim l_iCurrentIndex = m_hashLoadedAssemblies(p_strAssemblyName)
            Dim l_InvokedAssembly As System.Reflection.Assembly = m_rgAssemblies(CInt(l_iCurrentIndex))
            Dim l_Type As Type
           
            'assign the type of the user selected assembly/class
            l_Type = l_InvokedAssembly.GetType(p_strAssemblyName + "." + p_strClassName)

            Dim l_ToInvoke As Object
            Dim l_xmlInput As New Xml.XmlDocument
            Dim l_xmlDocResult As New Xml.XmlDocument
           
            l_xmlInput.LoadXml("<test>test run</test>")
            
            'create and populate the input/output documents
            Dim l_InputDoc As Altova.IO.DocumentInput
            Dim l_OutputDoc As Altova.IO.DocumentOutput
            l_InputDoc = New Altova.IO.DocumentInput(l_xmlInput)
            'create an instance of the user selected assembly/class
            l_ToInvoke = Activator.CreateInstance(l_Type)

            Try
            'invoke the RunDoc function
                l_ToInvoke.RunDoc(l_InputDoc, l_OutputDoc)
            Catch ex As Exception
                sendToLog("[invokeAssemblyMethod] An exception wast thrown while trying to invoke the selected assembly method.")
                sendToLog("[invokeAssemblyMethod] " + ex.Message.ToString)
            End Try


Unfortunatly when attempting to call RunDoc I get the following exception:

"Method invocation failed because 'Public Sub RunDoc(input2Source As Altova.IO.DocumentInput, output2Target As Altova.IO.DocumentOutput)' cannot be called with these arguments:
Argument matching parameter 'input2Source' cannot convert from 'DocumentInput' to 'DocumentInput'."

Am I trying to do something totally whacked? Or am I just doing something wrong at some point? Any feedback and/or suggestions would be greatly appreciated!

Use of the Altova User Forum(s) is governed by the Altova Terms of Use.