c# - Calling base class of a class in an assembly loaded into a seperate app domain -


i've been fighting few days , can't find on google particular situation. know want possible because have worked application (exit game photon) photon unfortunately not run under linux , have far why i'm trying "re-invent wheel)

i have program loads assembly (plugin type of thing) seperate app domain pulls interface , can run fuctions defined in interface on class in assembly assembly class inherits base class in assembly. want able run fuction on base class without having add derived class exception

base class:

[serializable] public abstract class applicationbase : marshalbyrefobject, iapplicationbase {     public abstract void setup();     public virtual void teardown() { }     public virtual void onstoprequested() { }      public virtual void onserverconnectionfailed(int errorcode, string errormessage, object state)     {         //do nothing individual servers     } } 

test server class:

public class testserver : applicationbase {     protected readonly ilogger log = logmanager.getlogger("testserver");      public override void setup()     {         log.debug("setup");      }      public override void teardown()     {         log.debug("teardown");     }      public override void onserverconnectionfailed(int errorcode, string errormessage, object state)     {     }      public override void onstoprequested()     {         log.debug("stop requested");     } } 

now can call of setup, teardown, onstoprequested, or onserverconnectionfailed plugins class overrides them. , logger output. if put like:

public void configure(string val1, string val2)     {         //initialize values     } 

in base class, after instantiate plugin following code:

applicationpath = $"{deploypath}\\{appconfig.basedirectory}\\bin";         if (!file.exists(applicationpath + "\\" + appconfig.assembly + ".dll")) console.writeline("error {0} not found", appconfig.assembly);         appdomainsetup adsetup = new appdomainsetup         {             applicationbase = applicationpath,             applicationname = appconfig.name,             privatebinpath = applicationpath,             shadowcopyfiles = "true",             shadowcopydirectories = applicationpath         };         _appdomain = appdomain.createdomain(string.format("{0} appdomain", appconfig.assembly), null, adsetup);         _application = (iapplicationbase)_appdomain.createinstanceandunwrap(appconfig.assembly, appconfig.type); 

if try call _application.configure("one","two"); following exception:

unhandled exception: system.missingmethodexception: method not found: 'void empirehostruntimeinterfaces.iapplicationbase.configure(system.string, system.string)'. @ socketserver.program.start() @ socketserver.program.main(string[] args)

this iapplicationbase interface:

public interface iapplicationbase {     void configure(string val1, string val2);     void setup();     void teardown();     void onserverconnectionfailed(int errorcode, string errormessage, object state);     void onstoprequested(); } 

now can tell throwing exception because base class defines function , not direved class i'm going release other other people use , need call function in base class because needs transparent derived class (it sets information main server config pass down sub application)

anything put in base class can access plugins derived class (for example if put public string applicationname = "application1" in base class , call log.debug(applicationname); in derived class shows value of whats in base class can't figure out life of me how call base classes constructor arguments

i tried passing arguments createinstanceandunwrap threw no constructor found exception

not sure if "proper" way figured out way creating serializable class call applicationdata fields need instantiating new applicationdata class , adding appdomain data area wich base class in plugin can access

applicationdata data = new applicationdata {applicationname = appconfig.name, binarypath = applicationpath}; _appdomain.setdata("data", data); 

then in base class added parameterless constructor:

protected applicationbase() {     _appdata = (applicationdata)appdomain.currentdomain.getdata("data"); } 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -