Reference going missing in Remoted Object

  • Thread starter Thread starter Nick Zdunic
  • Start date Start date
N

Nick Zdunic

I have a remotable object running in my host application.



The host starts up and creates the object. Within a method to start the
remote object doing its thing it creates an object.



This object reference is passed into another object create within the same
method.



A sample of remote object goes something like this:



Public Sub Start()



_microListener = New TcpClient



_microHub = MicroControllerHub.GetInstance()



_microHub.SetTcpClient(TcpClient)



End Sub



The microListener is passed into the _microHub (which is a Singleton)



The microListener object seems to be alive in the calling object but for
some reason the reference is lost

In the _microHub object.



Any remoting experts out there who can help?
 
Hi Nick

We have reviewed this issue and are currently researching on it. We will
update you ASAP. Thanks for your patience!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Slight error in example:

_microHub.SetTcpClient(TcpClient)

should read:

_microHub.SetTcpClient(_microListener)

Anyway - I have some further information add. The Host object doesn't seem
to lose the object reference to TcpClient. I know this as the host has
started the object running and send the time out through the socket every 10
seconds.

I have a client application which can obtain a refrence to the _microHub
object and display the contents of it on a form.

However, when the client attempts to call a specific method on this object -
I get the object not there type of error message. This method call utilises
the TcpClient reference - which should be there because the timer code in
the client is using it.
 
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.
 
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
 
MicroHub is inherited from CollectionBase - does this marshal correctly or
does it implement the same functionality as MarshalByRefObject. It is does
then this probably wont fix the problem.
 
Peter - I have tried amending the MicroHub to inherit off MarshalByRefObject.

However I think the problem is more related to CollectionBase. I still get
the same problem as the underlying collection in this object is an object of
this type. I think the curencymanager is not being updated with it's current
position. The serialization would appear to work correctly.
 
Hi,

Thanks for your input.

To isolate the problem and have you tried my sample in my last post.
Also to locate the problem more quickly, I think you may try to wrap the
MicroHubObj in the MicroHub collection as a field or in an arraylist in the
MicroHub to see if the problem persists.

Can you modify the code I provide in my last post and send back to me by
removing "online" from my email address so I can do further troubleshooting.

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.
 
Back
Top