views:

235

answers:

1

I have an OLEVariant disguised as a .Net object that I recieve from a client-side component over the net. I know that the contents are an array of bytes, but I don't know how to convert those contents to a native .Net byte array (byte[]). Any clues on how I can accomplish the conversion?

Edit: We answered our own question. To take an OleVariant (of type array of bytes) to a .Net byte[] requires pumping the object as it comes in into a .Net Array, taking the Array's upper bounds, creating a new byte[] of upperbound size and then finally doing an Array.Copy().

A: 

Cast the object to byte[] with (byte[])myobj or myobj as byte[] .

Jesse C. Slicer
Someone care to explain the downvote? I've done this exact code between Delphi and C#.
Jesse C. Slicer
Don't know where the downvote came from. In any case, I tried casting and it didn't work. Maybe I did something wrong. I'll check again.
William Daniel
I just went and reviewed this code - it goes back to mid-2008, but what I see is a Delphi COM+ server returning an OleVariant (not sure if Delphi's OleVariant type is different than OLEVariant) and the C# literally just has byte[] result = controller.Result as byte[]. The .NET side was using an auto-generated COM proxy class to talk to the controller, which I think must have been returning the result as type Object. Sorry I don't have any more tidbits to assist.
Jesse C. Slicer
That's fine. What we did works, though, and for he record, to take an OleVariant (of type array of bytes) to a .Net byte[] requires pumping the object as it comes in into a .Net Array, taking the Array's upper bounds, creating a new byte[] of upperbound size and then finally doing an Array.Copy().My thanks for the answer. I'll edit the question.
William Daniel