How to tell .methode with one to take?

D

De Roeck

Thanks for reading,

I've got the following function:

Private allFlags As BindingFlags = BindingFlags.Public Or
BindingFlags.NonPublic Or _
BindingFlags.Static Or _
BindingFlags.Instance

Public Shared Function StartAUT(ByVal applicationPath As String, ByVal
typeName As String) As Object
Dim aTtype As Type =
Assembly.LoadFrom(applicationPath).GetType(typeName)
Dim obj As Object = Activator.CreateInstance(type1)
aType.GetMethod("Show", allFlags).Invoke(obj, Nothing)
Return obj
End Function

When I give as applicationPath a simple form (afrom.exe) then there
are by default two show-methods

1. show()
2. show(IWin32Window)

The program is giving an execption and complaining that he found two
methods.

I want to invoke the first one, that without parameters.
How can I do that, what do I wrong?

They already told me that I can use follow code to have the same
result:

------
For Each m As MethodInfo In typeUT.GetMethods("Show", allFlags)
If m.GetParameters().Length = 0 Then
mi = m
Exit For
End If
Next
------

I think that the problem is that I don't give the correct "empty"
parameter, and would like to know the sollution in VB.

I found the following C# code with do correctly, but I need it in VB.

C#
------
Assembly asm = Assembly.LoadFrom(applicationPath);
Type typeUT = asm.GetType(typeName);
object obj = Activator.CreateInstance(typeUT);
MethodInfo mi = typeUT.GetMethod("Show", allFlags);
mi.Invoke(obj, null);
Return obj;
 
G

Guest

here's the C# block in VB.net maybe this will get you started

Dim asm As Assembly = Assembly.LoadFrom(applicationPath)
Dim typeUT As Type = asm.GetType(typeName)
Dim obj As object = Activator.CreateInstance(typeUT)
Dim mi as MethodInfo = typeUT.GetMethod("Show", allFlags)
mi.Invoke(obj, Nothing)
Return obj
 
D

De Roeck

WerD, thanks for your reply..

I've used the code you've provided, but then I received an
AmbiguousMatchException.

So you do not take the method without parameters (and do not know with
one to take)


So I'm still here with the problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top