I have a .NET assembly DLL that is created on-the-fly from pre-compiled code in a database. Is there a way to create the DLL file, put data into it, load it with the Assembly
class, then when the process exits, have that DLL be deleted?
My first thoughts were to open it with the FILE_SHARE_DELETE
flag, load it with Assembly.LoadFrom,
and have it automatically be deleted.
Although LoadLibrary does open files with the FILE_SHARE_DELETE
flag, when the DLL is still mapped in memory, the OS will not delete the file.
So, how can the DLL be deleted when the process exits without using AppDomains
or starting external "delete this file after target process exits" executables (the .NET DLLs that load at runtime depend on user input, so doing this would involve some kind of process communication, which I would like to avoid).