Replace DLL while application is running

Is it possible to update a DLL while a service is running that uses the DLL ? Or does the service have to be stopped before the DLL can be replaced.
acousticsateliteAsked:
Who is Participating?
 
athapaCEO / CTOCommented:
If it is in use by the service then you can't replace the dll. If you just need to replace the dll but don't need to use the new dll then your service could copy the dll to temp location and load from there in the startup. So the actual dll can be replaced. But if you want to be able to update and load a new dll without restarting your app then you should try to load the dll in different appdomain. Whenever you need to update the dll, close the appdomain, change the dll, create a new appdomain, and load the dll in the new appdomain.

AT
0
 
AgariciCommented:
you can change the dll while the app is runing only if you load the dll at runtime into a different appdomain.

appDomain = AppDomain.CreateDomain("MyNewDomain");
assembly = appDomain.Load("dllToLoadDyn");
SomeType = assembly.GetType( "dllToLoadDyn.SomeType" );

// do whatever with the dll

AppDomain.Unload( appDomain );

hth,
A.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.