Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
215 views
in Technique[技术] by (71.8m points)

asp.net - System.Reflection.Assembly.LoadFile Locks File

I'm loading a DLL via System.Reflection.Assembly.LoadFile and reflecting over it's members in a plugin-esque system. I need to be able to update/overwrite these DLL while the system is running but it appears that after calling System.Reflection.Assembly.LoadFile the file is subsequently locked.
Does anyone know of a way to unlock the file?
I have read about loading the file in a separate appdomain? Are there any pitfalls to this approach?

question from:https://stackoverflow.com/questions/1031431/system-reflection-assembly-loadfile-locks-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you use this:

 System.Reflection.Assembly.Load(System.IO.File.ReadAllBytes(path))

It will not lock the file.

Edit


While this works, it is not the best solution, but the better way of doing it is a lot more involved (too much for just pasting all the code here for it).

I have created a public repository on Github here with all the code for doing this properly:

Loading Assemblies without Locking by using Shadow Copying.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...