473,320 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

assembly method invoke

Expand|Select|Wrap|Line Numbers
  1. Assembly assembly = Assembly.LoadFrom(@"D:\Work\ex\project5stepwrapper.dll");
  2.                 foreach (Type Cls in assembly.GetTypes())
  3.                 {
  4.                     if (Cls.IsInterface)
  5.                         continue;
  6.                     object instance = Activator.CreateInstance(Cls);
  7.                     foreach (MethodInfo Method in Cls.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
  8.                         foreach (ParameterInfo pi1 in ((MethodInfo)Method).GetParameters())
  9.                             string returnValue = (string)Method.Invoke(instance, new object[] { pi1 });
  10.                   }
---------------------------------------------------------------
error message is comming :

Object of type 'System.Reflection.RuntimeParameterInfo' cannot be converted to type 'System.String&'.

any such solution to be appreciated and i shall be greatfull........
Mar 18 '10 #1
4 2849
Frinavale
9,735 Expert Mod 8TB
Check out the ParameterInfo Class for an explanation on how to use it, complete with an example.

-Frinny
Mar 18 '10 #2
@san1907
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Private m_Street As String
  3.  
  4. Public Function GetNameBlank() As String
  5. GetNameBlank = "Hello World"
  6. End Function
  7.  
  8. Public Function GetName(SomeString As String) As String
  9. GetName = SomeString
  10. End Function
  11.  
  12. Public Property Let Street(ByVal strNewStreet As String)
  13. If Len(strNewStreet) = 0 Then Err.Raise 5
  14. m_Street = strNewStreet
  15. End Property
  16.  
  17. Public Property Get Street() As String
  18. Street = m_Street
  19. End Property
  20.  
---------------------------------------------------------------------------
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 :
-------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. Assembly assembly = Assembly.LoadFrom(@"D:\Work\ex\project5stepwrapper .dll");
  2. foreach (Type Cls in assembly.GetTypes())
  3. {
  4.   if (Cls.IsInterface)
  5.     continue;
  6.   object instance = Activator.CreateInstance(Cls);
  7.   foreach (MethodInfo Method in Cls.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
  8.     if (String.Compare(Method.Name, "GetName", false) == 0)
  9.     {
  10.       var parameters = new List<object>();
  11.       foreach (ParameterInfo pi1 in ((MethodInfo)Method).GetParameters())
  12.       {
  13.         if (pi1.ParameterType == typeof(string))
  14.           parameters.Add("test");
  15.       }
  16.       object returnValue = Method.Invoke(instance, parameters.Count == 0 ? null : parameters.ToArray());
  17.  
  18.       if (returnValue != null)
  19.         Trace.Assert(true, returnValue.ToString());
  20.     }
  21. }
------------------------------------------------------------------------------------
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.Reflection.RuntimeParameterInfo' cannot be converted to type 'System.String&'
-----------------------------------------------------------------------------------
if it solved then try to call this .net class library in vb6.0
--------------------------------------------------------------------------------------
Mar 22 '10 #3
MrMancunian
569 Expert 512MB
Did you even read what Frinavale handed you? Perhaps you could respond to that by telling us what you did with that information?

Steven
Mar 23 '10 #4
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.dll

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
Mar 24 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: James Thurley | last post by:
I'm trying to dynamically compile assemblies and cache them to disk, which seems to work fine. When the data I'm compiling from changes, I want to re-generate the assembly and use the new version....
2
by: Michel Schilthuizen | last post by:
Hi, I am working on an application that can use functionlity in some sort of plugins. I have implemented this by using Assembly.LoadFrom and MethodInfo.GetMethods. The calling of the plugins...
2
by: Martin Maat | last post by:
Hi, I am trying to create a plug-in assembly without the need to register it in the GAC. Reflection should help me out here. I got this far: private void button1_Click(object sender,...
1
by: Ajay Pal Singh | last post by:
Hi, I am making an windows service similar to windows task schedular. The service would invoke the methods of some assemblies at some predefined schedules. (windows service read the...
3
by: Manfred Braun | last post by:
Hi All, I am able to invoke some methods from an instance of a loaded assembly, but I am not able to invoke the loaded assemblie's "Main" method. I try it this way: Assembly assembly =...
7
by: Gaetan | last post by:
I would like to extend the capabilities of my application by calling a user method residing in a client provided assembly without having to recompile my application. Things would work like this:...
1
by: tlwright1414 | last post by:
I'm trying to late bind and invoke a method on a .net 2.0 assembly from a .net 1.1 assembly. I'm getting and error 'The format of the file 'myAssembly.dll' is Invalid. Can't figure it out. Any...
3
by: binder.christian | last post by:
Hi! I have two applications: * mainapp.exe * plugin01.exe I have 2 "friend" variables in mainapp.exe: Friend gblConn as SqlConnection Friend gblPath as string
7
by: uncle | last post by:
config file that contains lines like... assemblyname|classname|methodname I want to invoke that static method. I found the following examples which make sense... Type theClass =...
1
by: =?Utf-8?B?VGVycnkgSG9sbGFuZA==?= | last post by:
I am using the following code to execute a method of a class in an assembly Public Shared Function NewPerson() As TZ_Interfaces.IPerson 'This factory will return an instance of clsPerson with...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.