0

Looks like I'm trying to do something that other's haven't run into again. Atleast, from Google searching it seems like this is pretty unique.

I have a server running with a directory full of dlls. Each dll is used to process a certain type of order and managed by different people. When an order comes in, there is a table that determines which dll to spin up, run it and then spin it down (free from memory).

The process we started with was:

  • Create an AppDomain
  • Load needed dll into the domain
  • Run the code we need
  • Unload the AppDomain

The issue we had with this was the server would run out of memory or we would get "token errors". I think the issue is that we call some 3rd party pascal dlls I don't think are getting freed.

We updated our the process to:

  • Create an AppDomain on process load
  • Load the dll into this "global" AppDomain
  • Run the dll's code

This got rid of our memory issues and we have recieved zero token errors. However, when we want to move a dll from our test server to our production server we have to kill the whole service, and then the dlls are not locked in memory. Then reprocess any orders that died with the service and any that came in while the service was down.

I've worked with the group and tried to unload the AppDomain, but once it is unloaded it doesn't just free dll's that are running, it basically kills the whole domain. I've considered moving this dll loader to it's own System.Process, so that the OS can clean up the memory when the process ends. However, I'm not sure how to have one Process run code in another Process. This plan seems like basic OS security features would prevent it because virus' would have a heyday.

Does anyone have an idea how we can run dll's in an AppDomain and then having them unlocked from memory so that they can be updated? (Without creating and disposing many AppDomain because they don't seem to clean everything up.) It would be great to have a memory pool that I can nuke and but .NET isn't about manual memory management.

Questionable
  • 768
  • 5
  • 26
  • Load each DLL in its own process. Use any IPC mechanism of choice to transfer requests (not code). Keep the processes alive as long as possible -- it's massively inefficient to start a new one for each request unless the requests themselves are very intensive to process, and very infrequent. (This is true even if you use the lighter mechanism of AppDomains.) Cleanly updating DLLs can be done by implementing a special request for it in the main (orchestrating) process, including exiting, copying a new version, starting and buffering requests while all of this happens. – Jeroen Mostert Sep 13 '21 at 19:59
  • Does this answer your question? [Hot Unload/Reload of a DLL used by an Application](https://stackoverflow.com/questions/4887847/hot-unload-reload-of-a-dll-used-by-an-application) – Dmitry Sep 13 '21 at 20:32
  • Sadly no, but @JeroenMostert comment I think will get me where I need to go. Thanks! – Questionable Sep 13 '21 at 21:05

0 Answers0