c# - Create App Domain to use with plugins: "Type in assembly is not marked as serializable -
i'm trying enable capability of using plugins in wpf application. far understanding goes, need (well, not need, it's suggested) create additional app domain.
for this, i'm doing following on startup in app.xaml.cs:
private void loadplugins() { // create , polish plugin app domain appdomain pluginappdomain = appdomain.createdomain("myproject plugin container", null); pluginappdomain.unhandledexception += pluginappdomain_unhandledexception; //todo: load plugins dlls } private void pluginappdomain_unhandledexception(object sender, unhandledexceptioneventargs e) { logger.fatalexception("pluginappdomain", e.exceptionobject exception); }
but attaching unhandledexception event fails exception:
type 'myproject.app' in assembly 'myproject, version=1.0.0.0, culture=neutral, publickeytoken=1337' not marked serializable.
what issue?
.net remoting needs access pluginappdomain_unhandledexception
child appdomain. pluginappdomain_unhandledexception
instance method , child appdomain needs access through current object (this) class. there 2 ways this. 1 have class derive marshalbyrefobject allow it's instances accessed other appdomains via proxies. other way decorate class serializableattribute , let .net remoting know instance of class can serialized other appdomains. why serializable error. class not 1) derive marshalbyrefobject
, 2) not marked serializable
.
as far know isn't idea subscribe event different appdomain
. see if make class , class of logger
derived marshalbyrefobject
still long way solution because passing exceptions between appdomains. work need all exceptions passed between appdomains serializable , assemblies loaded in both appdomains. might problem if want isolate plugins.
if first make application plugin-aware without dealing separate appdomains. whole thing concering appdomains , unhandleexceptions quite complicated.
then might try approach marshalbyrefobject
derived objects (only logger enough if pluginappdomain_unhandledexception made static) , pass strings logger
's methods.
otherwise give separate log plugin or use windows event log.
Comments
Post a Comment