Hi, The attached C# file demonstrates a small problem we currently encountered using IronPython 2.7.4:
We have a C# method which has two overloads - one is parameterless, and the other one has a single out parameter. For non-generic methods, it is possible to call both variants when calling with and without clr.Reference, but this does not work for generic methods. When trying to call the parameterless generic method directly, the following exception appears: Microsoft.Scripting.ArgumentTypeException was unhandled HResult=-2146233088 Message=Multiple targets could match: Method(), Method() Source=Microsoft.Dynamic StackTrace: [snipped] The workaround is to use the .Overloads[] syntax: print instance.Method[str].Overloads[()]() Btw, trying "print instance.Method[str].Overloads[int]()" leads to the following funny ArgumentTypeException: "Method() takes at least 2147483647 arguments (0 given)" Best regards Markus Schaber CODESYS® a trademark of 3S-Smart Software Solutions GmbH Inspiring Automation Solutions 3S-Smart Software Solutions GmbH Dipl.-Inf. Markus Schaber | Product Development Core Technology Memminger Str. 151 | 87439 Kempten | Germany Tel. +49-831-54031-979 | Fax +49-831-54031-50 E-Mail: m.scha...@codesys.com | Web: http://www.codesys.com | CODESYS store: http://store.codesys.com CODESYS forum: http://forum.codesys.com Managing Directors: Dipl.Inf. Dieter Hess, Dipl.Inf. Manfred Werner | Trade register: Kempten HRB 6186 | Tax ID No.: DE 167014915 This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
 namespace AmbigousCall { using System; using IronPython.Hosting; using Microsoft.Scripting.Hosting; class Program { const string SRC = @" import clr print instance.Plain() print instance.Plain(clr.Reference[int]()) print instance.Method[str](clr.Reference[int]()) print instance.Method[str]() "; static void Main(string[] args) { ScriptEngine engine = Python.CreateEngine(); ScriptScope mainScope = engine.CreateScope(); mainScope.SetVariable("instance", new TwoMinded()); engine.Execute(SRC, mainScope); Console.ReadLine(); } } public class TwoMinded { public int Plain() { return 1; } public int Plain(out int anotherInt) { anotherInt = 2; return 3; } public T Method<T>() { return default(T); } public T Method<T>(out int anotherInt) { anotherInt = 0; return default(T); } } }
_______________________________________________ Ironpython-users mailing list Ironpython-users@python.org https://mail.python.org/mailman/listinfo/ironpython-users