Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 29th, 2003, 08:57 AM
Registered User
 
Join Date: Oct 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Error: "Ambiguous match found"

I used the code above to create a dinamic instace os a class "MyType":
Code:
using System;
using System.Reflection;



class MyType {

   public void Hello() {

      Console.WriteLine("Hello world!");

   }

}



class TheApp {

   public static void Main() {

      Console.Write("Create an object using Activator.CreateInstance");

      String typeName = "MyType";

      String methodName = "Hello";

      // create the MyType object, by the name!

      Type t = Type.GetType(typeName);

      // create an instance of that type, ok the actual type is known only at run time ('dinamically')

      Object obj = Activator.CreateInstance(t);


      // call the requested method

      t.GetMethod(methodName).Invoke(obj, null);

   }

}
But if the method "Hello()" have an overload like this:

Code:
   public void Hello() {

      Console.WriteLine("Hello world!");

   }

}
   public void Hello(int Id) {

      Console.WriteLine("Hello world"+ Id.ToString() + "!");

   }

}
the code return the error "Ambiguous match found" when the line
Code:
      t.GetMethod(methodName).Invoke(obj, null);
is executed.

I have tried use an object[] with the params of the method hello but don´t work too.

What´s the problem with the code??

Thank´s
 
Old October 29th, 2003, 01:59 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

If you have VS.NET installed, try this link. It demonstrates how to call overloaded methods of a dynamically created object.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old November 7th, 2006, 03:45 AM
Authorized User
 
Join Date: Oct 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to salemkoten
Default

Hi Imar,
I have the same problem, I have tried to link this link above but I can't.
Could you help me?
SLKT

 
Old November 7th, 2006, 06:58 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

I think the on-line version of that page can be found here:
http://msdn.microsoft.com/library/de...nvoketopic.asp

Cheers,

Imar





Similar Threads
Thread Thread Starter Forum Replies Last Post
Compilation Error: 'Global' is ambiguous?? reidcor BOOK: ASP.NET Website Programming Problem-Design-Solution 10 November 26th, 2008 05:34 PM
template match doesnt match the required node Tomi XSLT 2 March 12th, 2007 06:24 AM
Type Miss match error for Server.CreateObject Deepmala Classic ASP Components 0 December 6th, 2005 02:50 AM
Type miss match error Deepmala Classic ASP Databases 0 December 6th, 2005 02:36 AM
Compier Error: procedure decleration does'nt match haahoou Beginning VB 6 2 January 20th, 2004 03:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.