c# - Subscring to events in an isolated WPF add-in -
i have isolated wpf add-in. addin gets reference type exposes event. since addin isolated in specific appdomain, host knows nothing addin's dll, or types stored there.
contract:
[addincontract] public interface iaddincontract: icontract { void initialize(iaddinhandler handler); }
handler type exposes event, , derives marshalbyref, proxy passed addin:
public class addinhandler : marshalbyrefobject, iaddinhandler { public event selectionchangedeventhandler selectionchanged; }
and in addin like:
public override void initialize(iaddinhandler handler) { handler.selectionchanged += handler_selectionchanged; }
however fails, tries (somehow) pass reference of addin host application, , since host, addin's dll unknown, fails load type , throws exception. how can still maintain isolation, , able described above?
i had similar problem , solved in following way:
for add-in contract, didn't used c# eventing pattern using delegates. used "java-like" event registration pattern, means created interface 1 method (interface needs implement icontract), created in contract 2 methods addeventhandler , removeeventhandler. both requires instance of created interface. in adapters, create adapter between delegate , interface implementation.
Comments
Post a Comment