assembly method invoke

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • san1907
    New Member
    • Mar 2010
    • 3

    assembly method invoke

    Code:
    Assembly assembly = Assembly.LoadFrom(@"D:\Work\ex\project5stepwrapper.dll");
                    foreach (Type Cls in assembly.GetTypes())
                    {
                        if (Cls.IsInterface)
                            continue;
                        object instance = Activator.CreateInstance(Cls);
                        foreach (MethodInfo Method in Cls.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
                            foreach (ParameterInfo pi1 in ((MethodInfo)Method).GetParameters())
                                string returnValue = (string)Method.Invoke(instance, new object[] { pi1 });
                      }
    ---------------------------------------------------------------
    error message is comming :

    Object of type 'System.Reflect ion.RuntimePara meterInfo' cannot be converted to type 'System.String& '.

    any such solution to be appreciated and i shall be greatfull...... ..
    Last edited by Frinavale; Mar 18 '10, 02:37 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Check out the ParameterInfo Class for an explanation on how to use it, complete with an example.

    -Frinny

    Comment

    • san1907
      New Member
      • Mar 2010
      • 3

      #3
      Originally posted by san1907
      Code:
      Assembly assembly = Assembly.LoadFrom(@"D:\Work\ex\project5stepwrapper.dll");
                      foreach (Type Cls in assembly.GetTypes())
                      {
                          if (Cls.IsInterface)
                              continue;
                          object instance = Activator.CreateInstance(Cls);
                          foreach (MethodInfo Method in Cls.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
                              foreach (ParameterInfo pi1 in ((MethodInfo)Method).GetParameters())
                                  string returnValue = (string)Method.Invoke(instance, new object[] { pi1 });
                        }
      ---------------------------------------------------------------
      error message is comming :

      Object of type 'System.Reflect ion.RuntimePara meterInfo' cannot be converted to type 'System.String& '.

      any such solution to be appreciated and i shall be greatfull...... ..
      Code:
      Option Explicit
      Private m_Street As String
      
      Public Function GetNameBlank() As String
      GetNameBlank = "Hello World"
      End Function
      
      Public Function GetName(SomeString As String) As String
      GetName = SomeString
      End Function
      
      Public Property Let Street(ByVal strNewStreet As String)
      If Len(strNewStreet) = 0 Then Err.Raise 5
      m_Street = strNewStreet
      End Property
      
      Public Property Get Street() As String
      Street = m_Street
      End Property
      ---------------------------------------------------------------------------
      this is the VB6.0 dll, name is : project5.dll
      convert it in wrapper using regsvr32, sn -k and tlbimp, name is : project5wrapper .dll
      ---------------------------------------------------------------------------
      then i wish to call this wrapper dynamically in .net in this way :
      -------------------------------------------------------------------------
      Code:
      Assembly assembly = Assembly.LoadFrom(@"D:\Work\ex\project5stepwrapper .dll");
      foreach (Type Cls in assembly.GetTypes())
      {
        if (Cls.IsInterface)
          continue;
        object instance = Activator.CreateInstance(Cls);
        foreach (MethodInfo Method in Cls.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
          if (String.Compare(Method.Name, "GetName", false) == 0)
          {
            var parameters = new List<object>();
            foreach (ParameterInfo pi1 in ((MethodInfo)Method).GetParameters())
            {
              if (pi1.ParameterType == typeof(string))
                parameters.Add("test");
            }
            object returnValue = Method.Invoke(instance, parameters.Count == 0 ? null : parameters.ToArray());
      
            if (returnValue != null)
              Trace.Assert(true, returnValue.ToString());
          }
      }
      ------------------------------------------------------------------------------------
      function GetNameBlank() and property Street are successfully invoke because they have no parameters
      but when invoking GetName(), an error messege is coming
      Object of type 'System.Reflect ion.RuntimePara meterInfo' cannot be converted to type 'System.String& '
      -----------------------------------------------------------------------------------
      if it solved then try to call this .net class library in vb6.0
      --------------------------------------------------------------------------------------
      Last edited by Frinavale; Mar 22 '10, 12:51 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.

      Comment

      • MrMancunian
        Recognized Expert Contributor
        • Jul 2008
        • 569

        #4
        Did you even read what Frinavale handed you? Perhaps you could respond to that by telling us what you did with that information?

        Steven

        Comment

        • san1907
          New Member
          • Mar 2010
          • 3

          #5
          i have a COM type dll which developed in VB6.0 but i have no source code. my 90% project was developed in .net where 10% needed for completion. that's why 6 dll are required which are COM type and also each is dependent
          ex. HTMLEvent.dll -> HTMLSupport.dll -> HTMLInterface.d ll

          my ambition is
          1) convert COM type dll(unmanaged) to .net (managed) which was called wrapper(using regsvr32, sn -k, tlbimp)
          2) then the invoke all property and method signature in .net. if it is successfull
          3) developed body of the method and property
          3) delete the COM type dll and in which .net wrapper is added.

          so .net wrapper/any other replace my COM type dll

          Comment

          Working...