I'm trying to load assemblies into another appdomain (to be able to unload them when not needed) but also I want to be able to inspect types in the loaded assembly and create instances of my types (via Activator). Also I don't want the assemblies to get locked when loaded.
I don't see how this is possible. Things I have tried:
Loading Assembly.Load(File.ReadAllBytes(path)) helps me load an assembly without locking it, so it can get deleted/moved. This loads assembly into the current appdomain, so it won't be possible to unload it.
Creating another AppDomain and using AppDomain.Load() loads the assembly into a new AppDomain, but it is not possible to check all the types that are in the loaded AppDomain. I can't create anything, unless I know type fully qualified type name, and even then they have to either be Serializable or derive from MarshallByRef. Another AppDomain stuff just works via Proxies so it is harder to create things without having a Contract/Shared Interface, etc.
MEF also loads assemblies into the current AppDomain, so it is basically doing the same thing.
Mono.Cecil allows type inspection on a loaded assembly, but then I can't create types using TypeReference. Maybe if there was a way to convert TypeReference to Type?
I have checked how ILSpy does this, and to no surpirse it uses Mono.Cecil to load/unload the assembly, but then again, it does not create instances of any types, just does the type inspection which is possible going via Mono.Cecil route.
Now the question is, is this even possible? Am I missing anything?