I tried the below code to load and unload managed assemblies.
AppDomain dom = AppDomain.CreateDomain("some");
AssemblyName assemblyName = new AssemblyName();
assemblyName.CodeBase = pathToAssembly;
Assembly assembly = dom.Load(assemblyName);
Type [] types = assembly.GetTypes();
AppDomain.Unload(dom);
however, i got an exception "Friendlyname or appdomainbase invalid ", while loading the assembly into the appdomain. Can anyone help me
As the exception implies - it's just that it can't find the assembly.
You need to need to use the AppDomainSetup type when creating the AppDomain and set the ApplicationBase
to the folder where you want it to probe for assemblies when using the Load
method. You can also set the PrivateBinPath
as well for additional paths.
This other MSDN topic (linked from the previous one) gives an example.
Providing a CodeBase
in the AssemblyName will not work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.