Download dll to .net without blocking

I am working on a task in which I need to load a DLL and get some information from it, for example, class names, etc. .... but when I load this DLL into my code, it is blocked and cannot be created from the source code until I close the download program, I tried a specific solution, but none of them work for me

  • Shadow copy: in this case, when I collect a shadow copy, after that, if I changed something in
    my main dll will be still old in my download application.

  • System.Reflection.assembly.loadfrom (System.IO.GetBytes ("ASM path")); // work sometimes, but not always

  • System.Reflection.assembly.ReflectionOnlyConext (); // Doesn't work

Is there any right solution for this

+4
source share
2 answers

One way is to read the bytes of the file and use Assembly.Load overload, which takes an array of bytes, similar to what you do in your second example. I'm not sure System.IO.GetBytes , but try File.ReadAllBytes instead.

 byte[] assemblyBytes = File.ReadAllBytes("asm-path"); var assembly = Assembly.Load(assemblyBytes); 

However, this may not be enough depending on what you want to do, because you cannot unload the assembly after it is loaded. To get around this, if you need to, you can load the assembly into your AppDomain and then unload the AppDomain as soon as you are done with it.

 AppDomain ad = AppDomain.CreateDomain("New_Assembly_AD"); byte[] assemblyBytes = File.ReadAllBytes("asm-path"); var assembly = ad.Load(assemblyBytes); 

Once you are done with the assembly object, you can unload the AppDomain.

 AppDomain.Unload(ad); 
+19
source

Perhaps try to release the file after viewing the information? Thus, it can only be locked for a few milliseconds.

If this does not work. Copy the dll and use the copy ...

If you want to update information whenever the dll changes, you can write a directory listener and do something whenever the original dll has been updated.

+1
source

Source: https://habr.com/ru/post/1241594/


All Articles