jeudi 7 septembre 2017

Reflection: Initialize Object Issue

I added reference of one DLL in my project and was successfully able to access methods/classes of that DLL.

Code in DLL: (I do not have access to modify this code)

//Dll: myDllName
    Namespace myNamespace
        Public Class MyClass
                Private Sub New(ByVal parameter1 As Int64)
                    //Set some values
                End Sub

                Public Shared Function MyPublicFunction(ByVal Parameter1 As Int64,ByVal Parameter2 As INt64,ByVal Parameter2 As Int64) As MyClass
                Dim retMyClass As New MyClass(Parameter1)
                //Set Other Values

                Return retMyClass
          End Function

          Public Function Post() As Boolean
            //Do some operation
          End Function
        End Class
    End Namespace

My code where I have called above DLL:

Dim myObj As myDllName.myNamespace.MyClass
myObj = myDllName.myNamespace.MyClass.MyPublicFunction(Parameter1, Parameter2, Parameter3)

myObj.Prop1 = MyVal1
myObj.Prop2 = MyVal2
myObj.Prop3 = MyVal1
myObj.Post()

Now my requirement is I want to achieve above task without adding reference of DLL to the project. So I tried to achieve this with reflection.

Dim assembly As Reflection.Assembly = Reflection.Assembly.LoadFile("..\\myDllName.dll")
Dim t As Type = assembly.GetType("myDllName.myNamespace.MyClass")
Dim woFacadeinst As Object = Activator.CreateInstance(t)

But on object initialization it throws me error that Constructor on type

myDllName.myNamespace.MyClass

not found.

I think it is because of the Private NEW method in my DLL reference class. Can someone help with this?





Aucun commentaire:

Enregistrer un commentaire