Willem de Jong
Willem de Jong

Reputation: 964

Dynamically update dlls on running instance

We have a service running that connects with hundreds of devices over TCP. Every time we want to do an update of this service we need to restart it and this causes a connection loss for all devices.

To prevent this we want to divide our application into a connection part and a business logic/datalayer part. This will give us the option to update the business logic/datalayer without restarting the connection part. This could be done with WCF services, but the system should response as fast a possible and introducing another connection to something will cause an extra delay.

Would it be possible to update a dll file without restarting the application and give the application an instruction so it will load the new dll and discharge the old one? Off course as long as the interface between the layers don't break.

Upvotes: 0

Views: 1021

Answers (2)

goroth
goroth

Reputation: 2610

Here is a good example of loading / unloading assembly dynamically.

http://www.c-sharpcorner.com/uploadfile/girish.nehte/how-to-unload-an-assembly-loaded-dynamically-using-reflection/

Be careful about speed since the MethodInfo.Invoke is slow you might want to look into using DynamicMethod. Also creating / destroying app domains is slow.

http://www.wintellect.com/blogs/krome/getting-to-know-dynamicmethod

Also you can use what is called a "plugin" framework. Codeplex has one called the MEF "Managed Extensibility Framework"

http://mef.codeplex.com/

Upvotes: 0

OnoSendai
OnoSendai

Reputation: 3970

According to MSDN:

"There is no way to unload an individual assembly without unloading all of the application domains that contain it. Even if the assembly goes out of scope, the actual assembly file will remain loaded until all application domains that contain it are unloaded."

Reference: http://msdn.microsoft.com/en-us/library/ms173101(v=vs.90).aspx

My approach would probably involve some sort of local communication between communication layer and business logic, each on a different context (AppDomain) - via named pipes or memory mapped files, for example.

Upvotes: 1

Related Questions