Simple question - how to use AppDomainSetup.PrivateBinPath prop?(FW2.0)

Spark

Newcomer
Joined
Dec 1, 2004
Messages
4
Situation: I have non-strong-name library _1Lib.dll and want to load it
in new domain. Startup app - just console app with code:

Code:
using System;
using System.Reflection;

namespace _1Main
{
	class Program
	{
		static void Main(string[] args)
		{
			AppDomainSetup domSetup2 = new AppDomainSetup();
			domSetup2.ApplicationBase =
			AppDomain.CurrentDomain.BaseDirectory;
			domSetup2.PrivateBinPath = "P1";
			AppDomain anotherAD2 =
			AppDomain.CreateDomain("SecondAppDomain", null, domSetup2);
			anotherAD2.Load("_1Lib");
			Console.ReadKey();
		}
	}
}
And how folders organized:

c:\MyDir\_1Main.exe << Startup app
c:\MyDir\P1\_1Lib.dll << Lib I want to load

But code above just thow "System.IO.FileNotFoundException crossed an
AppDomain boundary". Message of exception: "Could not load file or
assembly '_1Lib, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null' or one of its dependencies." But if I move
_1Lib.dll to the c:\MyDir\ (so both _1Main.exe and _1Lib.dll appear
in the same folder) code work just fine. But I really need to place lib
in SUB-folder of MainApp-folder!! Help!!

Thanks.
 
Have you tried
C#:
domSetup2.PrivateBinPath = IO.Path.Combine(Application.StartupPath, "P1");
instead of
C#:
domSetup2.PrivateBinPath = "P1";
 
marble_eater said:
Have you tried
C#:
domSetup2.PrivateBinPath = IO.Path.Combine(Application.StartupPath, "P1");
instead of
C#:
domSetup2.PrivateBinPath = "P1";

I try - and no success. :o The same FileNotFoundException.... And besides, from MSDN:
AppDomainSetup.PrivateBinPath Property
Gets or sets the list of directories under the application base directory that are probed for private assemblies.
So, my guess, StartupPath added automatically by framework. In any case - any new ideas about "how to use PrivateBinPath correctly"?
 
I don't know much about loading a DLL into a different domain, but doing a Google on AppDomain Load FileNotFoundException produced a couple of articles that sound to me like you're not supposed to be trying what you're trying?

For example, from one article by Brad Adams, a Program Manager at MS:
AppDomain.Load() is only meant to be called on the current AppDomain (for use by Interop callers).

Sorry I'm not more help...

-nerseus
 
Nerseus said:
For example, from one article by Brad Adams, a Program Manager at MS:
-nerseus

Hmm... Sound reasonably. From MSDN:
AppDomain.Load Method (String)
public Assembly Load (
string assemblyString
)

.....
This method should only be used to load an assembly into the current application domain.

OK, but... does this mean that answer to question "how to load new assembly(.dll) into new domain if assembly(.dll) situated in sub-folder of app-main-folder" will be "impossible"?!
 
Back
Top