tags:

views:

125

answers:

1

Hello,

I am calling a function from a .NET assembly which returns a byte[]

how do I capture the return value of that function ?\

I tried doing this

byte[] byteData = (byte[])obj.GetType().GetMethod("methodname").Invoke(obj, new object[] { buffer});

but I get a null value back in byteData ..

Can anybody help ?

+4  A: 

If it's genuinely returning a non-null byte array, that should be absolutely fine.

Are you sure it isn't filling the buffer you've provided, instead of returning a new byte array?

Here's a demo of it working:

using System;

class Test
{
    public byte[] GiveMeBytes()
    {
        return new byte[2];
    }

    static void Main()
    {
        object obj = new Test();
        byte[] byteData = (byte[])obj.GetType().GetMethod("GiveMeBytes")
                                     .Invoke(obj, new object[0]);
        Console.WriteLine(byteData.Length); // Prints 2
    }
}
Jon Skeet
Thanks Jon .. Yes that's what I thought .. I might be doing something else wrong .. I will do a little bit more digging
GX