ByVal object parameters not modified over Remoting

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi All,

I've discovered a strange behaviour with Object parameters passed
ByVal via remoting and I'm wondering if anybody could shed some light
on this.

In a non remoting function call, when a object (as opposed to a value
type like Integer, Boolean, etc) is passed as a ByVal parameter, it's
content can be modified. This is somehow "strange", but I've lived
with that so far.
Now when the exact same function is called via remoting (i.e. the
parameter will be serialized for the call) the content of the object
is NOT modified. It looks a bit inconsistent to me and I'd like to
know if I'm missing something. Or is there a way I can change this
without having to use ByRef.
Code sample below.

Thanks
JB

<Serializable()> _
Class CTest
Public Value As String
End Class

Public Sub ChangeValueByVal(ByVal Test As CTest)
Test.Value = "Value Has been changed by the Sub (ByVal)"
End Sub

Public Sub ChangeValueByRef(ByRef Test As CTest)
Test.Value = "Value Has been changed by the Sub (ByRef)"
End Sub

Dim Test As New CTest

'In Non Remoting Environement (i.e. ChangeValueByVal and
ChangeValueByRef called locally)
'====================================================================
Test.Value = "Initial Value"

ChangeValueByVal(Test)
'Upon exit Test contains "Value Has been changed by the Sub (ByVal)"
'<== OK

ChangeValueByRef(Test)
'Upon exit Test contains "Value Has been changed by the Sub (ByRef)"
'<== OK

'So Far so Good...
'Now In a Remoting Environement (i.e. ChangeValueByVal and
ChangeValueByRef called remotely)
'=======================================================================
Test.Value = "Initial Value"

ChangeValueByVal(Test)
'Upon exit Test contains "Initial Value" '<== Inconsistent, why is
that !!!!

ChangeValueByRef(Test)
'Upon exit Test contains "Value Has been changed by the Sub (ByRef)"
'<== OK

.



Relevant Pages

  • RE: ByVal object parameters not modified over Remoting
    ... reference type byval, in process, simply sends the reference, allowing the ... Public Sub ChangeValueByVal ... 'Upon exit Test contains "Value Has been changed by the Sub " ... ChangeValueByRef called remotely) ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Windows Service Remoting Question
    ... The remoting framework ... Why you don't see anything in the event log I'm ... Do you see the "Application Server Registered" entry in the log ... > Sub Main ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: Reference vs Value vs Marshalling vs Subroutines on Server .. design question
    ... > value to the caller) In a non remoting environment this works however ... > the modifications made to the object by sub. ... ByRef, so if the SUB change it, it will affect the passed object. ...
    (microsoft.public.dotnet.framework.remoting)
  • Showing a Form using a timer
    ... I am creating an application that will create a notify window similar to ... outlook 2003 notify popup. ... Private Sub ATU_RetrieveDone(ByVal e As ... GetUpdate creates a new thread and begins the remoting call ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Reference vs Value vs Marshalling vs Subroutines on Server .. design question
    ... and caller never sees the difference. ... value to the caller) In a non remoting environment this works however ... so it appears to be working by reference and not by value. ... I tried passing them ByRef to that same SUB (this worked when server ...
    (microsoft.public.dotnet.framework.remoting)