AppDomain Probing issue

A

A. Elamiri

Hello,

I created a small app which acts as a services manager. I basically drop a
DLL in a Services folder and set the frequency through the application for
how often do I want the code in the assembly to run (scheduler).

I created a seperate AppDomain here is the code:
....
AppDomainSetup ads = new AppDomainSetup();
string path =
Application.ExecutablePath.Replace(System.IO.Path.GetFileName(Application.Ex
ecutablePath),"");
ads.ApplicationBase = path + "Services";
ads.PrivateBinPathProbe = path + "Services";
ads.PrivateBinPath = path + "Services";
ads.DisallowBindingRedirects = true;
Tools.ShowInfo(path);
SvcBin = AppDomain.CreateDomain("ServiceAssemblies",null,ads);

....

The above code was placed in the constructor. When I look through the
assemblies (GetAssemblies) to see a listing of all classes loaded, I don't
see the classes in the dll located in that services folder, which made me
think that it is not being probed. Anything I'm doing wrong?
 
K

Ken Kolda

The code you have by itself won't cause the assemblies in the Services
folder to be loaded -- it just creates a AppDomain. The assemblies will be
loaded the first time you create an instance of an object from one of them
(e.g., with AppDomain.CreateInstance()) or when you explicitly load them
(e.g., with AppDomain.Load()).

Ken
 
A

Abhishek Srivastava

In the code you have posted you have created the domain. but you haven't
loaded the assembly yet.

On the created domain you should call Load and pass the assembly which you
are trying to load as a param.

This time you don't have to pass any path information because that was
already supplied to the AppDomainSetup object.

regards,
Abhishek.
 
A

A. Elamiri

Thanks for the replies, but now I'm getting a different error

Additional information: Insufficient state to deserialize the object. More
information is needed.

this occurs at this line
OwnerForm.SvcBin.Load("ClintonServices");

SvcBin is an AppDomain created by the OwnerForm, OwnerForm is simply the
parent windows form
 
K

Ken Kolda

When you call AppDomain.Load() from a different AppDomain than the one in
which the assembly is loaded, you can often run into this problem. What's
happened is the assembly is indeed loaded into the other app domain. But, it
then attempts to return the assembly reference to the calling AppDomain.
That requires the calling AppDomain to load the assembly as well. But, since
the assembly isn't in the calling AppDomain's probing path (current
directory), the load fails.

Ken
 
S

Sunny

Hi Ken,

just curious (never had to deal with this) - how the you load an
assembly in the new appdomain without loading it in the calling one?

Sunny
 
K

Ken Kolda

I've done this using the AppDomain.DoCallback(). Make sure the delegate is
marshal-by-value and have the delegate that's invoked call
AppDomain.CurrentDomain.Load(). Of course, that means the new appdomain will
have to load the assembly that contains the definition of the class
containing the delegate, so hopefully that's acceptable.

Ken
 
S

Sunny

Thanks

ken.kolda@elliemae- said:
I've done this using the AppDomain.DoCallback(). Make sure the delegate is
marshal-by-value and have the delegate that's invoked call
AppDomain.CurrentDomain.Load(). Of course, that means the new appdomain will
have to load the assembly that contains the definition of the class
containing the delegate, so hopefully that's acceptable.

Ken
 

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