Geeks With Blogs

News My Blog has been MOVED to https://mfreidge.wordpress.com
Michael Freidgeim's OLD Blog My Blog has been MOVED to https://mfreidge.wordpress.com
It is well known, that in .Net value type parameters are passed by value, and reference type parameters are passed by reference(more detailed and strict description can be found here).
I thought(even after a year working with application that extensively uses Remoting)  that .Net Remoting calls do the same. But I was wrong!
Recently I found that a method with custom class parameter  doesn't have one of the properties updated after return, even if it is certainly updated inside the method.

I've read a few reference articles.
quickstart Remoting Overview is a little bit confusing:
Object passing. All objects created remotely are returned by reference and have to derive from MarshalByRefObject. Objects passed as parameters to a remote method call can be forwarded by value or by reference. The default behavior is pass by value provided the object in question is marked by the custom attribute [Serializable]. Additionally, the object could implement the ISerializable interface, which provides flexibility in how the object should be serialized and deserialized. Objects that are not marshal by reference or marshal by value are not remotable.
 

How to marshal an object to a remote server by value by using Visual C# is more clear:

Because parameter ForwardMe does not inherit from MarshalByRefObject, it is passed by value to the server.

And finally, article  Copying, Cloning, and Marshalling in .NET clarified it:

By default, all objects in .NET (both value- and reference-types) are marshalled by value when sent across the "wire" to a remote AppDomain.To override this default MBV behavior, one can simply derive one's class from System.MarshalByRefObject .

So the Rules for passing parameters in .Net Remoting are the following:

1. Parameter should have attribute [Serializable] or derive from MarshalByRefObject.
(It would be unusual for a class to be both marked with the serializable attribute and extend MarshalByRefObject.)

2. If parameter is serializable, it is passed by value. Changes inside remote methods do not return to the client.

3. If parameter  derive from MarshalByRefObject , it is passed by reference.

4. I am not sure, what happens If you specify modifier ref  for serializable parameter. I hope that it is also passed by reference, but not sure.

The following links discuss how parameters are treated in WCF:

How to pass a reference in WCF 

Preserving Object Reference in WCF  

Posted on Saturday, May 10, 2008 10:26 PM .Net Remoting | Back to top


Comments on this post: Passing parameters in .Net Remoting

# re: Passing parameters in .Net Remoting
Requesting Gravatar...
Useful and clear info. Thank you!
Left by Jon on Jun 14, 2011 2:08 AM

Your comment:
 (will show your gravatar)


Copyright © Michael Freidgeim | Powered by: GeeksWithBlogs.net