When marshaling objects between AppDomains in .NET the CLR will either serialize the object (if it has the Serializable
attribute) or it will generate a proxy (if it inherits from MarshalByRef
)
With strings however the CLR will just pass the reference to the string object into the new AppDomain. The CLR still ensures integrity since .NET strings are immutable and any change by the second AppDomain to the string will not effect the original object.
Which brings me to my question: is there a way to tell the CLR that my custom type is immutable and when used in remoting it should just pass the reference to the object as it does with the string class?