I don't think that was the problem. Another object (one of mine) which
inherits from MarshalByRefObject has the same problem.
I have made some mods and the problem doen't occur anymore.
The code was working something like this.
- get a reference to remote object called PacketListener - this is running
as a remote object
- call a method called Start on this object
- get a refrence to an object called MicroHub which is created within the
Start method
- Display the contents of MicroHub on a grid using binding - this works fine
- Call Method Send on MicroHub reference. This would fail. Any object
within MicroHub would be set to nothing (not just TcpClient as mentioed
previously)
The change to the code results in a slightly different process:
- get a reference to remote object called PacketListener - this is running
as a remote object
- call a method called Start on this object
- get a refrence to an object called MicroHub which is created within the
Start method
- Display the contents of MicroHub on a grid using binding - this works fine
- Call Send on PacketListener. This method was moved to PacketListener and
uses the reference to MicroHub which is in the PacketListener residing in
the remote host. This works.
It seems that calling methods on the secondary object (MicroHub) would not
work when those methods contain code which reference a module level object
in MicroHub
However going through PacketListener - the object created by the client
through remoting - this works.
HOWEVER
I have another problem. The MicroHub object displays fine in a grid. This
MicroHub object contains a collection of micro instances. MicroHub inherits
from a base object I created called DomainCollectionBase which in turn
inherits from CollectionBase and implements IBindingList. The micro object
inherits from a class called DomainBase which in turn inherits from
MarshalByRefObject and implements IEditableObject.
Now the contents are displayed fine. However retrieving a value from micro
is causing a problem. I use a CurrencyManager to track movement in the
grid. I use this to get the currently selected micro in the collection.
This works - but using a value with micro is not working. An integer
property called ControllerID in this object is always returning zero no
matter which row I select in the grid. My non- remotong version of the
program always returns the right value. Other properties exhibit similar
behaviour.
What could be going wrong?
Nick
""Peter Huang"" <v-******@online.microsoft.com> wrote in message
news:k7**************@cpmsftngxa10.phx.gbl...
Hi Nick,
I think to pass an object by reference to an remote instance, we need to
declare the object class inherited from MarshalByRefObject. So that it can
across the AppDomain.
While TCPClient is not inherited from MarshalByRefObject, so it can not
across the appdomain. In remoting programming, the client and the host
will
be in two different appdomain.(similar with the process in the traditional
win32 programming).
For your senario, I think you may try to wrap the TCPClient in an
MarshalByRefObject
e.g.
public class MyRemoteObject : MarshalByRefObject
{
public TCPClient tc;
public MyRemoteObject()
{
tc = new TCPClient();
}
}
You may have a try and let me know the result.
Can you tell me why you need to pass an TCPClient by reference to remoting
object?
Best regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no
rights.