Hello,
I'm trying to use this as a script engine for a test tool where I'm
basically populating a combo box with all public methods available in
the script and executing the methods as if they were individual
scripts onto themselves. This tool will be loading and unloading
different script files, so I would like to use the Remoting pattern.
Also, I've decided to use an instantiated class instead of a static
class because I can then use inheritance and put some framework code
in a base class contained within my host application.
Also, I won't know what methods will be in each script file until
runtime, so all methods must be executed using pure reflection.
Unfortunately the pattern I've chosen seems to be one that has no
examples. I did figure out how to get all this working (after several
days of pain), but now I'm stuck.
My problem is that no matter what I do, 5 minutes after the script is
loaded, I get a Remoting exception indicating that the object has been
disconnected.
Object [...] has been disconnected or does not exist at the server.
After doing some research, I found that I need to handle the
LifetimeService lease on the object. I believe I've done everything
correctly, except now I'm at a point where things just don't make
sense. I believe I've properly gotten the LifetimeService reference
from myScriptInstance. I'm certain this works because I am able to
change the timeout in various ways to a shorter time period from the
default 5 minutes and the object properly expires. The problem is no
matter what method I use to extend the lifetime of my script it still
expires at the end of the 5 minutes.
This leads me to believe that there is some other object that I don't
have control over that isn't managing its lifetime service. I think
it has something to do with AsmHelper, but I haven't been able to
track it down yet. I tried exposing the asmBrowser object from
AsmHelper and handling the lifetime of that, but it didn't seem to fix
my issue either. Either I did that wrong or there is some other
object that needs to be dealt with.
This is really irritating to debug because every test I do takes 5
minutes.
Here's what I've tried:
From the script: Overriding the InitializeLifetimeService() and
setting up different parameters seems to work in that I can SHORTEN
the lifetime, but if I try to extend it, after 5 minutes it still
dies.
From the script: Overriding the InitializeLifetimeService() and
returning null still causes the script to die after 5 minutes.
From the host: calling ScriptInstance.GetLifeTimeService() allows me
to get a lifetime object that I can control. Again, I can shorten the
lifetime, but if I try to extend it, after 5 minutes it dies.
From the host: calling ScriptInstance.GetLifeTimeService() and
registering a sponsor seems to work. I’ve shortened the lifetime, and
at the end of that I see the sponsor’s Renewal method fire and renew
properly. After 5 minutes it still dies regardless of the renewals.
From the host: calling any method causes a renewal, but after 5
minutes
Here's an article discussing my issue with various solutions.
http://www.codeproject.com/Articles/18997/Remoting-Architecture-in-NET
asmFile = CSScriptLibrary.CSScript.Compile("dynamicscript.cs", null,
true);
CSScriptLibrary.AsmHelper helper = new
CSScriptLibrary.AsmHelper(asmFile, "ScriptDomain1", true);
object myScriptInstance = helper.CreateObject("*");
helper.InvokeInst(myScriptInstance, "*.Initialize", this);
string[] methodnames = (string[])helper.InvokeInst(myScriptInstance,
"*.GetMethodNames");
ScriptLease = (ILease)ScriptInstance.GetLifetimeService();
//I've tried several methods here and they all seem to properly affect
the lifetime of the myScriptInstance object, but I can't access my
script after 5 minutes.
//Use a sponsor object to continually renew the lease
ScriptSponsor = new ClientSponsor();
ScriptLease.Register(ScriptSponsor);
//Try just renewing the lease for a year
ScriptLease.Renew(TimeSpan.FromDays(365));
Any help would be greatly appreciated. Thanks.
Joe