I’m using c# 4.0 and a console application just for testing, the following code does gives an exception.
AppDomainSetup appSetup = new AppDomainSetup()
{
ApplicationName = "PluginsDomain",
ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
PrivateBinPath = @"Plugins",
ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
};
AppDomain appDomain = AppDomain.CreateDomain("PluginsDomain", null, appSetup);
AssemblyName assemblyName = AssemblyName.GetAssemblyName(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins", "sample.dll"));
Assembly assembly = appDomain.Load(assemblyName); //This gives an exception of File not found
AppDomain.Unload(appDomain);
I keep getting File not found exception when using Load on my created AppDomain.
Thanks.
I think i’v figured out why this happens, thats because the current domain needs to load the assembly too even if your loading the assembly in a diffrent app domain, the current domain needs to know about it and load it, thats because how the .NET was designed.
check here for details.
http://msdn.microsoft.com/en-us/library/36az8x58.aspx
and when i checked the fusion logs, i found that the newly created app domain was successfully able to load the assembly from the private bin path, and the reason why you still get the exception of “File not found”, because this exception belongs originally to the current app domain.
that means if you copied the assembly in current application path or to the path where the current domain is probing, you will find that you can load the assembly into your custom domain.
Hope that helps.