473,395 Members | 1,404 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,395 software developers and data experts.

More than one method is found with VB but not with C#

Hi,

I've want to launch an application by reflection and get his handle
back.

But when I run this code in C# then it's handled correctly.
The application(-path) is started on a new thread and obj is the hwnd
of the started application.

private static BindingFlags allFlags = BindingFlags.Public |
BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance;

public static object StartAUT(string applicationPath, string typeName)
{
try
{
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;
}
catch{}
return null;
}

but when I launch this code in VB.NET than I received an
AmbiguousMatchException execption.
Private Shared 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
Try
Dim asm As System.Reflection.Assembly =
System.Reflection.Assembly.LoadFrom(applicationPat h)
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
Catch
End Try
Return Nothing
End Function
What do I wrong?

Greetings,
Davy
Oct 29 '06 #1
5 1127
You are catching any exception that might occur in the method and
ignoring it. Start by at least throwing the exception again, so that you
see it.

De Roeck wrote:
Hi,

I've want to launch an application by reflection and get his handle
back.

But when I run this code in C# then it's handled correctly.
The application(-path) is started on a new thread and obj is the hwnd
of the started application.

private static BindingFlags allFlags = BindingFlags.Public |
BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance;

public static object StartAUT(string applicationPath, string typeName)
{
try
{
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;
}
catch{}
return null;
}

but when I launch this code in VB.NET than I received an
AmbiguousMatchException execption.
Private Shared 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
Try
Dim asm As System.Reflection.Assembly =
System.Reflection.Assembly.LoadFrom(applicationPat h)
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
Catch
End Try
Return Nothing
End Function
What do I wrong?

Greetings,
Davy
Oct 29 '06 #2
When I go through all the methods with .methods,
then I found in VB-language two methods with that name,
but only 1 in C# (and there should only one)

On Sun, 29 Oct 2006 17:11:31 +0100, Göran Andersson <gu***@guffa.com>
wrote:
>You are catching any exception that might occur in the method and
ignoring it. Start by at least throwing the exception again, so that you
see it.

De Roeck wrote:
>Hi,

I've want to launch an application by reflection and get his handle
back.

But when I run this code in C# then it's handled correctly.
The application(-path) is started on a new thread and obj is the hwnd
of the started application.

private static BindingFlags allFlags = BindingFlags.Public |
BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance;

public static object StartAUT(string applicationPath, string typeName)
{
try
{
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;
}
catch{}
return null;
}

but when I launch this code in VB.NET than I received an
AmbiguousMatchException execption.
Private Shared 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
Try
Dim asm As System.Reflection.Assembly =
System.Reflection.Assembly.LoadFrom(applicationPa th)
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
Catch
End Try
Return Nothing
End Function
What do I wrong?

Greetings,
Davy
Oct 29 '06 #3
I think both C# and VB are right from there respective points of view.
C# is case sensitive, VB is not.

So, when you have a function named "Show" and another function named
"show" in the assembly, and you are asking for the info of the method
"Show", then C# will find one and VB will find two.

If you add the flag BindingFlags.IgnoreCase to the c# version, I think
you will also get 2 functions in C#.
De Roeck wrote:
When I go through all the methods with .methods,
then I found in VB-language two methods with that name,
but only 1 in C# (and there should only one)

On Sun, 29 Oct 2006 17:11:31 +0100, Göran Andersson <gu***@guffa.com>
wrote:
>You are catching any exception that might occur in the method and
ignoring it. Start by at least throwing the exception again, so that you
see it.

De Roeck wrote:
>>Hi,

I've want to launch an application by reflection and get his handle
back.

But when I run this code in C# then it's handled correctly.
The application(-path) is started on a new thread and obj is the hwnd
of the started application.

private static BindingFlags allFlags = BindingFlags.Public |
BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance;

public static object StartAUT(string applicationPath, string typeName)
{
try
{
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;
}
catch{}
return null;
}

but when I launch this code in VB.NET than I received an
AmbiguousMatchException execption.
Private Shared 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
Try
Dim asm As System.Reflection.Assembly =
System.Reflection.Assembly.LoadFrom(applicationP ath)
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
Catch
End Try
Return Nothing
End Function
What do I wrong?

Greetings,
Davy
Oct 29 '06 #4
I've futher analysed the differences and found that in Reflector that
there are two Show-methods

Public Sub Show()
Public Sub Show(ByVal owner As IWin32Window)

I want to invoke the first one, that without paramaters
so I use:

VB.NET
-------
Dim asm As System.Reflection.Assembly =
System.Reflection.Assembly.LoadFrom(applicationPat h)
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)
------

But he also invoke the second method (of show).

when I run the same in C# then he only invokes that one without
paramters:

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);
------

How to tell VB that he has to invoke only those without parameters?
Oct 29 '06 #5
I've futher analysed the differences and found that in Reflector that
there are two Show-methods

Public Sub Show()
Public Sub Show(ByVal owner As IWin32Window)

I want to invoke the first one, that without paramaters
so I use:

VB.NET
-------
Dim asm As System.Reflection.Assembly =
System.Reflection.Assembly.LoadFrom(applicationPat h)
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)
------

But he also invoke the second method (of show).

when I run the same in C# then he only invokes that one without
paramters:

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);
------

How to tell VB that he has to invoke only those without parameters?
Oct 29 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: cody | last post by:
Does the clr allow more than one set and one get method for a property? Is it possible to use overloading for example set_Color(int c), set_Color(Color c)? from msdn: ...
2
by: Eric Newton | last post by:
VB's more declarative nature of handling events is golden. I'm hoping C# will acquire this type of deal, in addition to the anonymous delegates. could do same as vb (actually would be easier to...
161
by: KraftDiner | last post by:
I was under the assumption that everything in python was a refrence... so if I code this: lst = for i in lst: if i==2: i = 4 print lst I though the contents of lst would be modified.....
3
by: Ethan Strauss | last post by:
Hi, There have been quite a few discussions of Random not giving random numbers and how to fix that by feeding in a new seed each time, waiting enough time, or calling the Next() method of the...
0
by: Gabriel Genellina | last post by:
En Tue, 29 Jul 2008 08:45:02 -0300, Themis Bourdenas <bourdenas@gmail.com> escribi�: In a very strict sense, I'd say that all those references to "method decorators" are wrong - because...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.