Load and execute code from an assembly without locking the file?

吃可爱长大的小学妹 提交于 2019-12-11 07:38:58

问题


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:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/2886397/load-and-execute-code-from-an-assembly-without-locking-the-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!