Reputation: 4561
If I copy a file
File.Copy(src, dst);
and then load the copy
var asm = Assembly.LoadFile(dst);
Why are both files locked by my process?
If I delete the src before I load the dst, and then recopy the dst back to the src I get my desired end result. But the delete and copy seem a little unnecessary.
File.Copy(src, dst);
File.Delete(src);
var asm = Assembly.LoadFrom(dst);
File.Copy(dst, src);
Yes I am building a plugin-design application. Yes I could be using AppDomains with Shadow Copy (http://msdn.microsoft.com/en-us/library/ms404279.aspx). Yes I will have to manage my own type cache (as each assembly load will give a different type as far as my AppDomain is concerned). But these are not answers to my question.
Note that src and dst are strings. No other stream is opened on the files.
Upvotes: 3
Views: 420
Reputation: 51359
It may be that the source file is in the assembly resolution path for your application, and so it is loaded automatically. Try making src C:\Temp
or some other path that has nothing to do with your application's folder, and see if the same thing occurs.
Upvotes: 2