Our app (C# WPF) is using some C++ libraries, and I'm trying to make it so that the dll could be replaced with a different version on app startup.
Simply replacing the file at startup, before it was referenced, worked, but it's not quite what I needed.
Then I tried to replace it while it's in use, i.e. renaming the current file, copying a new one under the original name – this way during the next startup a new version would be used. That does seem to work, but my question is – how reliable is it? From my testing, it seems that the file lock does allow renaming, but is it always the case? I don't wanna find out down the road that sometimes the lock is different and this doesn't work at all Sadly, I could not find anything in the MS documentation about this.
Of course an alternative (arguably the best way to go) would be LoadLibrary instead of DllImport, but that would require rewriting the wrapper and reloading during runtime is not really needed.