I am trying to load assemblies into a separate application domain, but I ran into a very strange problem. Here is the code:
public static void LoadAssembly(string assemblyPath) { string pathToDll = Assembly.GetCallingAssembly().CodeBase; AppDomainSetup domainSetup = new AppDomainSetup { PrivateBinPath = pathToDll }; AppDomain newDomain = AppDomain.CreateDomain("AssemblyLoader",null,domainSetup); AssemblyLoader loader = (AssemblyLoader)newDomain.CreateInstanceFromAndUnwrap( pathToDll, typeof(AssemblyLoader).FullName); }
AssemblyLoader is another class in the same assembly as this one, and it inherits MarshalByRef, however, for some strange reason, I get an exception exception every time I try to run this. I even hardcoded the path to the DLL instead of using GetCallingAssembly (). CodeBase yet I get this exception.
I understand that it is difficult to answer such a question without seeing it and not receiving additional information, but maybe someone has faced a similar situation and will know the general “gotchas” and what I should look for.
EDIT: The reason I don't want to download it directly is because it is just part of the code. The ultimate goal is that this class will have a method that loads assemblies, gets their GUID and some other information about them, and stores them in the database for the project I'm working on. Therefore, if I upload this assembly to a separate application domain, I can upload others there, and then unload the application domain. It makes no sense to download all these assemblies throughout the entire application if I only need this data.
Bfree
source share