I have been trying to serialize an array across an AppDomain
boundary, using the following code:
public int Read(byte[] buffer, int offset, int count)
{
return base.Read(buffer, offset, count);
}
As a guess, after noticing the attributes elsewhere, I marked the method's parameters with [In]
and [Out]
attributes, which seemed to cause the parameters to behave as if they were passed by reference.
For example:
public int Read([In, Out] byte[] buffer, int offset, int count)
{
return base.Read(buffer, offset, count);
}
Before I added the attributes, the contents of the buffer
variable were lost after returning from the method across an AppDomain
boundary.
The class (SslStream
) was inheriting from MarshalByRefObject
but not marked with the Serializable
attribute. Is this the only way to make a parameter pass-by-value? Are these attributes being recognised somehow by .NET when the class is being serialised? And do they truly cause the parameter to be passed by reference, or are the contents just copied?