473,569 Members | 2,790 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

assembly method invoke

3 New Member
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.Reflect ion.RuntimePara meterInfo' cannot be converted to type 'System.String& '.

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

-Frinny
Mar 18 '10 #2
san1907
3 New Member
@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.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
--------------------------------------------------------------------------------------
Mar 22 '10 #3
MrMancunian
569 Recognized Expert Contributor
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
san1907
3 New Member
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
Mar 24 '10 #5

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

Similar topics

0
1391
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. After I re-generate the assembly, I get the type I want from it and then invoke a static method. I have found the following behaviour: 1....
2
3215
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 is handled in threads. All works fine, but when I call a method that processes for some time, the mainthread (my form) becomes unresponsive.
2
13930
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, System.EventArgs e) { Assembly engine = null; AssemblyName assemblyName = new AssemblyName(); assemblyName.CodeBase = assemblyPath + @"Engine.dll";
1
3728
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 method/assembly and schedule info from app.config file) I am using reflection to dynamically load the assemblies and then want to call a method of that assembly...
3
6298
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 = Assembly.LoadFrom(config.exec.assemblyName); tRunnable = assembly.GetType(config.exec.typeName); object runner = assembly.CreateInstance("Demo"); Type...
7
2036
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- Read a configuration file where the client provides the assembly name (DLL) and the method name. 2- Detect the existence of the assembly...
1
1268
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 suggestions are much appreciated. Assembly p = Assembly.LoadFrom( asFilePath ); object o = p.CreateInstance( asClassName ); object args = new...
3
5356
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
1825
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 = assembly.GetType("Namespace.Classname", false, true); bool result = (bool)theClass.InvokeMember("Initialize", BindingFlags.Public | BindingFlags.InvokeMethod...
1
335
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 ID=intID 'from the BLL assembly defined in BLLCustomAssembly setting Dim strType As String = BLLCustomAssembly ' My.Settings.BLLCustomAssembly ...
0
7694
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7921
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7666
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6278
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2107
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.