By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,234 Members | 1,869 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,234 IT Pros & Developers. It's quick & easy.

How to tell .methode with one to take?

P: n/a
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(typeNam e)
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;
------
Thanks for helping.
Oct 31 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
"De Roeck" wrote:
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(typeNam e)
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;
------
Thanks for helping.
Nov 1 '06 #2

P: n/a
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.

On Tue, 31 Oct 2006 21:00:01 -0800, werD
<we**@discussions.microsoft.comwrote:
>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
"De Roeck" wrote:
>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(typeNa me)
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;
------
Thanks for helping.
Nov 1 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.