learner (1) [Avatar] Offline
Your book is very helpful. After reading comments and your reply on Amazon.com I think you made the right decision in including C# 2 in the book. I think without C# 2, it would have been incomplete.

I have observed a strange behavior on passing by value and reference and wanted to understand it better.

Lets say I have a function that takes a dataset(Plain old disconnected dataset) as a parameter and I am passing the dataset by value(so no ref or out keyword). This is a case of reference type passed by value.

Now, if I add a row in let's say table[0] inside the function then that row is reflected back to the callee. This I believe is the desired behavior.

But it does not behave the same way when the same function call is made using .NET Remoting.

The new row does not show up and it only shows up if the parameter is passed by 'ref' keyword.

Theoretically there should be no difference to the callee if the call is remote or not.

I would provide a sample but a remoting sample would be huge. Hope I explained the problem clearly.

If you experience the same behavior, my question is, is it a bug in .NET or is there some other explanation.

jon.skeet (448) [Avatar] Offline
Re: A Question on Passing parameters by Value
DataSet derives from MarshalByValueComponent. That means that when it is marshalled (to a different AppDomain or across any other remoting boundary) the values are copied rather than a reference - and any changes to the values are *not* copied back automatically.

Basically you need to "unlearn" a lot of stuff when it comes to remoting and cross-AppDomain work. It gets very tricky, I'm afraid - but I hope I've at least explained the behaviour you're seeing. Unfortunately MSDN isn't terribly helpful on MarshalByValueComponent but I suspect if you find a good article or book about .NET marshalling, it will explain it a lot better!


PS Thanks for the vote of confidence on the book smilie