I use Assembly.LoadFrom to load custom dll's, but one of these dll's is maintained in my project solution and is offered with the application.
The problem is that about every other time I try to build the project I get an error saying that it was unable to copy the newly compiled dll over the old one because it's being used by another process.
What's the best way to handle this? Two ideas that come to mind are:
- Copy the file to another location before loading it
- Just load the file into memory myself so I can manually close the file and then load the assembly from the in-memory copy.
Both of these solutions would be reasonably easy to implement, but I'd like it even better if there was an quick/easy approach that didn't require me to change my code.
Edit: I don't need to unload an assembly during runtime. When the program ENDS, I need it to release its lock on the dll file. I am perfectly aware of how AppDomains work and the pros of loading plugins into their own AppDomains, but for this particular application I'm not doing it that way.