Subscribing to events in assemblies loaded in separate appdomain?

G

galmok

Is it possible to subscribe to events loaded in a separate/secondary appdomain?

I have a working setup where I can call methods in assemblies loaded in a secondary appdomain and I can unload the secondary appdomain without problems, but when I try to subscribe to an event I have problems.

Basically what happens is that the secondary appdomain loads a new copy of the primary appdomain and fires the event into the second copy of the primary appdomain. This is of course not useful.

An actual code example is shown here (I judge it as too big for mail and it is better set up on the web):

http://stackoverflow.com/questions/22377654/subscribing-to-event-in-loaded-appdomain

Any pointers?
 
B

bradbury9

El jueves, 3 de abril de 2014 16:26:40 UTC+2, (e-mail address removed) escribió:
Is it possible to subscribe to events loaded in a separate/secondary appdomain?



I have a working setup where I can call methods in assemblies loaded in asecondary appdomain and I can unload the secondary appdomain without problems, but when I try to subscribe to an event I have problems.



Basically what happens is that the secondary appdomain loads a new copy of the primary appdomain and fires the event into the second copy of the primary appdomain. This is of course not useful.



An actual code example is shown here (I judge it as too big for mail and it is better set up on the web):



http://stackoverflow.com/questions/22377654/subscribing-to-event-in-loaded-appdomain



Any pointers?

Never worked with AppDomains, but the error message you describe:

{"Could not load file or assembly 'DynamicLoadTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.":"DynamicLoadTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"}

Is caused because the main ececutable does not find the assemblies, can be avoided:

- Coping the referenced assembies in running dir before executing
- Adding a reference to the assembly so VS makes the file copying for you
- Signing the assemby and storing it in the GAC

About the question, what i would try:

var instance = proxy.CreatePlugin(....);
instance.LoaderEventReceiver = this;
instance.TestEvent();
 
G

galmok

In my comments I wrote that I had tried copying the files into the same folder and while I am able to subscribe to the event, this causes the secondary appdomain to load the exe file (second copy of the primary appdomain) into its domain, leaving me with two seperate copies of the primary appdomain.When calling TestEvent, the event is handled by the second copy of the primary appdomain but I want the original primary appdomain to handle it. The primary appdomain and the copy of the primary appdomain do not share any variables.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top