Search:
Namespaces
Discussions
.NET v1.1
Feedback
Reference going missing in Remoted Object
Messages
Related Types
This message was discovered on
microsoft.public.dotnet.general
.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...
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?
Reply to this message...
Kevin Yu [MSFT] (VIP)
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."
Reply to this message...
Nick Zdunic
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.
"Nick Zdunic" <
Click here to reveal e-mail address
> wrote in message
news:e9y%c.23325$
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Peter Huang (VIP)
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.
Reply to this message...
Nick Zdunic
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"" <
Click here to reveal e-mail address
> wrote in message
news:
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Peter Huang (VIP)
Hi,
I think you may try to make MicroHub inherited from
MarshalByRefObject
to
see if this works for you.
I think the databindging may not be the root cause of the problem, so far
to isolate the problem, here I have an simple sample, you may have a try
and modify the code according to your idea to reproduce the problem as
simple as possible and send back to me.
Remotable Objects
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconRemotableObjects.asp
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.
Reply to this message...
Nick Zdunic (VIP)
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 Huang"" wrote:
[Original message clipped]
Reply to this message...
Nick Zdunic (VIP)
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.
""Peter Huang"" wrote:
[Original message clipped]
Reply to this message...
Peter Huang (VIP)
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.
Reply to this message...
System.AppDomain
System.Collections.CollectionBase
System.ComponentModel.IBindingList
System.ComponentModel.IEditableObject
System.MarshalByRefObject
System.Net.Sockets.TcpClient
System.Windows.Forms.CurrencyManager
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com