I have two app domains in my application: domain A and domain B. When application starts an object in A (objA) instantiates an object in B (objB) and calls a few methods on it. While application is running there are no calls from objA to objB. When application shuts down objA calls a method on objB. If application runs for some time (I have not figured out yet exact
numbers) a last call from objA to objB throws RemotingExeption: "Object 'blah-blah' has been disconnected or does not exist at the server." I overwrote InitializeLifetimeService to return null and now it seems to work with no exceptions. So my questions are:
1. After reading the article "Managing the Lifetime of Remote .NET Objects with Leasing and Sponsorship" I was under impression that if app domains are in the same process you do not have to manage leases. Where am I wrong
2. Is it correct to do the way I did (returning null from InitializeLifetimeService) Wouldn't it prevent objects from being garbage collected
Thank you,
Alex

Remoting in the same process and lifetime services
Dee Long
Yes, the sponsor solves it.
In my initial post I did not mention that objA creates domainB, then creates objB in domainB, makes a few calls to objB ant lets it run. When app is being shut down, objA calls a method on objB and the unloads domainB (no exceptions here, so domainB is running at the time call is made).
I think with my design (objB lives as long as the domain it runs in) I better off returning null from InitializeLifetimeServie vs. using sponsorship (extra unneeded lease related calls).
Or, if returning null from InitializeLifetimeServie is wrong, I could use spnsoship with large lease time (an hour or so).
Any comments
Alex
zpustc
Did the sponsor approach solve your problem. You had mentioned that you are trying to make a remoting call during shutdown. At what point are you making this call. Is it possible that the other AppDomain has already Shutdown
andrewfranchuk
In my opinion, returning null from InitializeLifetimeService is in general a problem - the object will never be cleaned up, even when it's not needed. Instead, I recommend to go ahead and sponsor objB from the objA object. That way, if objA ever goes away, then objB is free to be cleaned up. You can do this by implementing the ISponsor interface on objA, and then registering it as a sponsor like this:
using
System.Runtime.Remoting.Lifetime;using System.Runtime.Remoting;
....
public class objA : ISponsor{
ILease mLease;
//.. tons of code removed.
SponsorObjB(IobjB objB)
{
mLease = (ILease)RemotingServices.GetLifetimeService((MarshalByRefObject)objB);
mLease.Register(this);
}
#region
ISponsor Memberspublic TimeSpan Renewal(ILease lease)
{
return lease.InitialLeaseTime; // This is how long before the server checks again to see if the object is alive.
}
#endregion
}