Custom AppDomain and PrivateBinPath

Ahmed Galal picture Ahmed Galal · Jul 8, 2011 · Viewed 23.9k times · Source

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.

Answer

Mike Two picture Mike Two · Jul 8, 2011

First make sure Plugins is a subdirectory of your AppDomain base path. PrivateBinPath will only work on subdirectories as described here

If that isn't the problem then take a look at your fusion binding logs. Use the fusion log viewer There is also a good Blog Post on that. The fusion logs will tell you where it searched for the assembly. That should tell you if your path is included in the search.

One of the other possibilities is that it is finding your assembly but not one of its dependencies. Again the fusion log viewer will tell you.