I'm trying to create a small plugin framework, and have been going around and around the AppDomain code with not much luck.
The most important thing for me is that I want to have no conflicts between different versions of the same class (for example a plugin may want to use its own Common.dll v 1.0 library whereas I may have 2.0), similar to other issues.
So I wrote the small app below.
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Console.WriteLine(Utility.GetVersion());
var ads = new AppDomainSetup();
string appBase = @"../../ExtensionLib/ExtensionLib/bin/Debug";
ads.ApplicationBase = appBase;
var ad = AppDomain.CreateDomain("Extension App", null, ads);
Assembly a = ad.Load("ExtensionLib");
ILib l = (ILib) a.CreateInstance("LibImpl");
l.DoSomething();
Console.WriteLine(Utility.GetVersion());
}
}
Common.dll contains the Utility class, but we have different versions of that class. Both the plugin and the host application use the same ILib (defined on the same dll).
Host Application Setup
c:\....\123
Common.dll (v 2.0)
IntegInterface.dll (where ILib is defined, v1.0)
LoadCommon.exe (the host)
Plugin Application Setup
c:\....\456
Common.dll (v 1.0)
IntegInterface.dll (where ILib is defined, v1.0)
ExtensionLib.dll (the plugin)
When the app runs, I get an exception at the moment of ad.Load()
System.IO.FileNotFoundException was unhandled
Message="Could not load file or assembly 'ExtensionLib' or one of its dependencies. The system cannot find the file specified."
Source="mscorlib"
FileName="ExtensionLib"
FusionLog="Assembly manager loaded from: C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727\\mscorwks.dll
Running under executable C:\\Users\\Roberto\\Documents\\Visual Studio 2008\\Projects\\LoadCommon\\LoadCommon\\bin\\Debug\\LoadCommon.vshost.exe
--- A detailed error log follows. \n
=== Pre-bind state information ===
LOG: User = Roberto-PC\\Roberto
LOG: DisplayName = ExtensionLib\n (Partial)
LOG: Appbase = file:///C:/Users/Roberto/Documents/Visual Studio 2008/Projects/LoadCommon/LoadCommon/ExtensionLib/ExtensionLib/bin/Debug
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\\Users\\Roberto\\Documents\\Visual Studio 2008\\Projects\\LoadCommon\\LoadCommon\\ExtensionLib\\ExtensionLib\\bin\\Debug\\ExtensionLib.dll.config
LOG: Using machine configuration file from C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727\\config\\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
"
StackTrace:
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.AppDomain.Load(String assemblyString)
at System.AppDomain.Load(String assemblyString)
at LoadCommon.Program.Main() in C:\Users\Roberto\Documents\Visual Studio 2008\Projects\LoadCommon\LoadCommon\Program.cs:line 36
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
I also tried to setup an the assemblyresolve delegate to see if I could help, no luck however, I ended up with Serialization errors even though I did tag AssemblyHelper as serializable.
At some point I will also have the IntegInterface have different versions, and am sure I will end up with a whole slew of issues.
Can someone shed some light here? Very much appreciated.
Thanks