1

I have a c# function that I can call from IronPython. The function returns a byte array that I'd like to convert to a string for display and compare.

Python is telling me to pass the input parameter - (out Byte[] DataOut), below - as type "StrongBox[Array[Byte]]", so I converted "var" with

clr.Reference[Array[Byte]]() .

How do I convert this to a string?

namespace My_Library.My_Namespace
{
    /// </summary>
    public class My_App : OSI_Layer
    {

        public bool My_Function(out Byte[] DataOut)
        {

        // fill up DataOut with a string 

            return (Send(out DataOut));
        }

    // etc...
    }

}

//////////////////////////
//
// IronPython
//
// From IronPython I...

>>>
>>> import clr
>>> clr.AddReferenceToFileAndPath('My_Library.dll')
>>> from My_Library.My_Namespace import My_App
>>> App = My_App()
>>>
>>> from System import Array, Byte      
>>> var = clr.Reference[Array[Byte]]() # Create type StrongBox[Array[Byte]]"
>>>
>>> clr.Reference[Array[Byte]]
<type 'StrongBox[Array[Byte]]'>
>>>
>>> App.My_Function(var)
>>>
True
>>> var
<System.Byte[] object at 0x000000000000002B [System.Byte[]]>
>>>
>>> printable_var = System.BitConverter.ToString(var)

Traceback (most recent call last): File "", line 1, in TypeError: expected Array[Byte], got StrongBox[Array[Byte]]

onch
  • 43
  • 6

1 Answers1

0

You need to pass in the Value of the box, not the box itself.

printable_var = System.BitConverter.ToString(var.Value)
Jeff Mercado
  • 129,526
  • 32
  • 251
  • 272