|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to tell .methode with one to take?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; ------ Thanks for helping. 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 Show quoteHide quote "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(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; > ------ > > > Thanks for helping. > 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 <w***@discussions.microsoft.com> wrote: Show quoteHide quote >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(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; >> ------ >> >> >> Thanks for helping. >>
Why does activex control run 3x+ faster in vb5 than .net?
TCP Transfer issues system.net.mail Treeview doubleclick help From VB Newbie: The editor is driving me nuts. To create an instance of class in VB2005 Is application running? Help with Vb.net 2002 Update VB6 to VB.NET 2.0 Email Send ATTN: Seth Rowe follow up to startup path posting |
|||||||||||||||||||||||