Good day. There is a C # application in which managed and unmanaged dll files are loaded during work. It is necessary to implement a dynamic reload of these dll'ok. C managed dll problems do not arise - I create an additional domain and load them into it, and then unload the entire domain. Unmanaged dll'ki, as I understand it, do not interact with the domain and need a different mechanism. I tried to free them and load again with:

[DllImport("kernel32.dll", CharSet = CharSet.Auto)] static extern bool FreeLibrary(IntPtr hModule); [DllImport("kernel32.dll")] static extern IntPtr LoadLibrary(string dllToLoad); 

But when trying to reuse classes from these libraries, an Access Violation exception is thrown. I suspect that when using FreeLibrary, the libraries are unloaded, but there are pointers to them in clr and an exception is thrown when trying to use it.

The question is: is there any way to unload and reload the unmanaged dll and then use them.

  • Do you have to do FreeLibrary ? Can leave dll in memory? - nick_n_a
  • It is necessary to implement the update of these dll without restarting the program. For this and need to unload them from memory. - Nirah
  • "clr remain pointers to them" - on them it is not to the library. these are for memory areas, classes, bindings to descriptors, and so on. You need to free up / free all objects that contain references received by this library during the release. Either make a list of such objects (release / block the entire list), or somehow check the validity of the objects differently. - nick_n_a
  • Give an example of objects that depend on these libraries, then it will be clear where you lose links / objects and you can give more specific recommendations. - nick_n_a

0