views:

43

answers:

2

Is there a way to load an assembly from disk and execute code in it without getting the file locked on disk? I never understood why it is necessary to lock the file since the code will be loaded in RAM and JIT-compiled?

+1  A: 

What you are looking for is called shadow copying. You have to create a new AppDomain and provide an AppDomainSetup instance with the property ShadowCopyFiles set to the string true.

This application domain will copy the assemblies to a temporary location before loading them. See the MSDN for more details.

Daniel Brückner
+1  A: 

It's possible, you can use Assembly.Load(byte[]) to load an assembly as well. That assembly doesn't have a "loading context", you can load it repeatedly. Managing this is however not easy, you're bound to find out.

Hans Passant