[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.remoting

GetLifetimeService() is returning null

Shaun Wilson

9/4/2004 2:40:00 AM

I have a remote object named ObjectFactory that exposes a CreateInstance
method with some of the following code:



System.Runtime.Remoting.ObjectHandle objectHandle =
Activator.CreateInstance(assemblyName, typeName);

MarshalByRefObject mbr =
(MarshalByRefObject)objectHandle.Unwrap();

ILease lease = (ILease)mbr.GetLifetimeService();

String remoteHost = callerId;

ISponsor sponsor =
RemotingSponsor.GetHostSponsor(remoteHost);

lease.Register(sponsor);

return mbr;



My problem here is that "lease" is a null value,
mbr.GetLifetimeService() is not returning the default ILease object.



The client calls the above method to aquire object instances, some of
those objects are cached by the client, hence I must implement a sponsor
that knows when the client is lost (this way objects aren't expired
before the client is gone).



The objects being created do not implement GetLifetimeService, I am
relying on the default implementation provided by MarshalByRefObject
(which uses the LeaseManager for lease allocation).



I have considered that it may be caused by the fact that this object is
being created locally (at the server, rather than at the client), so
maybe there is a way to get this object to register itself with the
LeaseManager? However, I may be wrong and something else may be the
cause.



Alternatively I could populate a hashtable that retains an IList for
each client, and then place object references into the IList when
CreateInstance is called, thus preventing the GC from doing any cleanup.
When the client is lost I can clear the IList out and remove it from the
Hashtable, but this doesn't fit into the sponsorship model of .NET,
hopefully someone can help, I'm stuck. If I must manually register these
objects with the LeaseManager somehow I am willing to do this, but I am
not sure how.



Thanks!