Loading ...
Sorry, an error occurred while loading the content.

Problem invoking Method using COM enums

Expand Messages
  • Richard
    I am having a problem with late binding invoking of a method from a COM dll. Everything works fine as far as loading the dll creating an instance of the class.
    Message 1 of 1 , Feb 7, 2002
    • 0 Attachment
      I am having a problem with late binding invoking of a method from a COM dll.
      Everything works fine as far as loading the dll creating an instance of the
      class. I even have no problem invoking the method as long as it does not
      contain any enumerations in its parameters. This is where my problem lies.

      I have done testing and I can invoke methods with .NET enums but when it
      comes to using a COM dll it does not like its own enumerations at all. I get
      an error message specifying that the target type is not the same as the
      given type. I have tried a variety of different types to see if any match:
      System.Object, System.IntXX, Integer, Long, Enum itself. All these tried
      with no luck.

      I have included at the bottom code that I am using to invoke the method. If
      you have any ideas concerning a solution/workaround for this problem it
      would be much appreciated.

      Public Function InvokeMethod(ByVal assemblyFile As System.String, ByVal
      className As System.String, ByVal methodName As System.String, Optional
      ByVal args() As System.Object = Nothing) As System.Object
      Try
      Dim oAssembly As System.Reflection.Assembly =
      oAssembly.LoadFrom(assemblyFile)
      Dim oType As System.Type = oAssembly.GetType(className)
      Dim oMethodInfo As System.Reflection.MethodInfo =
      oType.GetMethod(methodName)
      Dim oInstance As System.Object =
      Activator.CreateInstance(oMethodInfo.DeclaringType)
      InvokeMethod = oMethodInfo.Invoke(oInstance, args)
      Catch eException As System.Exception
      Debug.WriteLine(eException)
      End Try
      End Function

      Richard
      rca@...
    Your message has been successfully submitted and would be delivered to recipients shortly.