mercredi 22 juillet 2020

C# Assembly.Load() method loads the wrong dll?

Problem Statement

I'm implementing some sort of a Shadow Copy in C# when loading dll, to prevent the dll file from being locked. It works as follows:

  1. Say I have sample.dll and want to load it into the appdomain without locking it
  2. First I make a copy of the assembly with the name sample_shadow.dll in the same directory
  3. Then I load sample_shadow.dll with Assembly.Load (Assembly.LoadFrom and AssemblyName.GetAssemblyName are also tried)
  4. After that, the loaded assembly appears to have a base location of sample.dll instead of sample_shadow.dll, and sample.dll is locked

Questions

  1. I'd like to know how can I load sample_shadow.dll correctly and thus prevent sample.dll to be locked
  2. I'd appreciate very much if someone can elaborate on the mechanisms in the background

Thanks in advance!

P.S. To load assembly with bytes is not an option due to the use of multiple dll and static variables (I think the load-bytes version missed some information compared to the load-with-file-name version of Assembly.Load)





Aucun commentaire:

Enregistrer un commentaire