internal static byte[] MarshalToBuffer(Object o)
{
// serialize headers and args together using the binary formatter
MemoryStream stm = new MemoryStream();
RemotingSurrogateSelector ss = new RemotingSurrogateSelector();
BinaryFormatter fmt = new BinaryFormatter();
fmt.SurrogateSelector = ss;
fmt.Context = new StreamingContext(StreamingContextStates.Other);
fmt.Serialize(stm, o, null, false /* No Security check */);
return stm.GetBuffer();
}