Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

GetMethod causes Ambiquous match found exception

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrus - 02 Sep 2007 19:21 GMT
Class MyClass contains a number of FindAll() methods in parent classes:

class MyClass: ActiveRecordBase<MyClass> {... }

public abstract class ActiveRecordBase<T> : ActiveRecordBase {
protected ActiveRecordBase();
public static T[] FindAll();
public static T[] FindAll(params ICriterion[] criteria);
public static T[] FindAll(DetachedCriteria criteria, params Order[] orders);
public static T[] FindAll(Order order, params ICriterion[] criteria);
public static T[] FindAll(Order[] orders, params ICriterion[] criteria);
...
}

public abstract class ActiveRecordBase : ActiveRecordHooksBase {
protected ActiveRecordBase();
protected internal static Array FindAll(Type targetType);
protected internal static Array FindAll(Type targetType, params ICriterion[]
criteria);
protected internal static Array FindAll(Type targetType, DetachedCriteria
detachedCriteria, params Order[] orders);
protected internal static Array FindAll(Type targetType, Order[] orders,
params ICriterion[] criteria);
...

I need to invoke MyClass parameterless FindAll() method using Reflection.
I tried the following code but GetMethod() returns Ambiquous match found
exception.
How to run parameterless FindAll() method ?
How to add required method signature to GetMethod() parameters or other
solution ?

Type t = Type.GetType("MyClass, MyDll");

// this line causes Ambiquous match found  exception :
MethodInfo mi = t.GetMethod("FindAll",
 BindingFlags.Public |
 BindingFlags.FlattenHierarchy |
 BindingFlags.Static);

IList<object> list = (IList<object>)mi.Invoke(null, null);

Andrus
Jon Skeet [C# MVP] - 02 Sep 2007 19:49 GMT
> I need to invoke MyClass parameterless FindAll() method using Reflection.
> I tried the following code but GetMethod() returns Ambiquous match found
[quoted text clipped - 10 lines]
>   BindingFlags.FlattenHierarchy |
>   BindingFlags.Static);

Use the overload of GetMethod which specifies the types of the
parameters:

MethodInfo mi = t.GetMethod("FindAll",  // Name
 BindingFlags.Public |                 // Flags
 BindingFlags.FlattenHierarchy |
 BindingFlags.Static,
 null,                         // Binder (default)
 new Type[0],                  // Parameter types (none)
 null);                        // Parameter modifiers (ignored)

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Andrus - 02 Sep 2007 23:27 GMT
> Use the overload of GetMethod which specifies the types of the
> parameters:
[quoted text clipped - 6 lines]
>  new Type[0],                  // Parameter types (none)
>  null);                        // Parameter modifiers (ignored)

Jon,

thank you.

Is'nt it better to use  Type.EmptyTypes  instead of new Type[0]  ?

Andrus.
Jon Skeet [C# MVP] - 03 Sep 2007 17:58 GMT
> thank you.
>
> Is'nt it better to use  Type.EmptyTypes  instead of new Type[0]  ?

Well, I find new Type[0] easier to understand personally - but it's
entirely your decision :)

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.