[Python.NET] Problem with System.ArgumentException in call to method from dll

brad at fie.us brad at fie.us
Wed Jan 23 15:23:00 CET 2013


Out of curiosity Barton, could you pass "None" rather than constructing instances?  Or does it truly need the argument to have a type in order to disambiguate overloaded methods?

Also, it is my understanding that in iPy, out parameters are often omitted from the method's arguments.  But in Python.Net they remain in the header.  I assume this is because removing the out parameters potentially creates a lot of ambiguity between overloads?

I'm wondering if it might be appropriate for PythonNet to define a type to make it possible to remove ambiguity.

i.e.:
c#:
public bool DoJob(int data1, int data2, out string result) { …}

python:
doer = Doer()
doResult = doer.DoJob(1,2,clr.OutParam(string))
if (doResult[0]):
   print(doResult[1])
else:
   print("error")

The key being: python net will never ever never let an OutParam object through to the clr.  Therefore, the following should throw an exception.

clr.OutParam(clr.OutParam)

Therefore, you would never run into reflective ambiguity.

On Jan 23, 2013, at 5:52 AM, Barton <barton at bcdesignswell.com> wrote:

> The Python.Runtime is a bit tricky when it comes to out parameters:
> In C# DateTime.TryParse(String, out DateTime) becomes
> 
> >>> d = DateTime(0)    # just a dummy to call the method on
> >>> d2 = DateTime(0) # another dummy to satisfy the out parameter (could be the same instance, d)
> # d3 is were the result is passed out
> >>> result, d3 = d.TryParse("2013/01/22", d2)
> >>> d3.ToString()
> u'1/22/2013 12:00:00 AM'
> >>> # this is the same behavior as iPy
> 
> 
> 
> I can't test this - I'm on Linux, but:
> Here you've given the type (class)
> from System.Windows.Media.Imaging import BitmapSource
> bitmapsrc = BitmapSource
> print bitmapsrc
> cam = xiCam()
> cam.OpenDevice(0)
> cam.SetParam(PRM.BUFFER_POLICY, BUFF_POLICY.SAFE)
> cam.SetParam(PRM.IMAGE_DATA_FORMAT,  IMG_FORMAT.MONO8)
> cam.StartAcquisition()
> timeout = 1000
> bitmapsrc = cam.GetImage(bitmapsrc, timeout)
> cam.StopAcquisition()
> ##
> 
> Console output:
> <class 'System.Windows.Media.Imaging.BitmapSource'>
> 
> What you need is an instance, perhaps:
> bitmapsrc = BitmapSource() # or something to that effect.
> 
> On 01/22/2013 11:58 AM, Daniel Krause wrote:
>> from System.Windows.Media.Imaging import BitmapSource
>> bitmapsrc = BitmapSource
>> print bitmapsrc
>> cam = xiCam()
>> cam.OpenDevice(0)
>> cam.SetParam(PRM.BUFFER_POLICY, BUFF_POLICY.SAFE)
>> cam.SetParam(PRM.IMAGE_DATA_FORMAT,  IMG_FORMAT.MONO8)
>> cam.StartAcquisition()
>> timeout = 1000
>> bitmapsrc = cam.GetImage(bitmapsrc, timeout)
>> cam.StopAcquisition()
>> ##
>> 
>> Console output:
>> <class 'System.Windows.Media.Imaging.BitmapSource'>
> 
> _________________________________________________
> Python.NET mailing list - PythonDotNet at python.org
> http://mail.python.org/mailman/listinfo/pythondotnet



More information about the PythonDotNet mailing list