Replace DLL while application is running

Posted on 2006-05-01
Last Modified: 2012-06-27
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.
Question by:acousticsatelite
    LVL 10

    Accepted Solution

    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.

    LVL 11

    Expert Comment

    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 );


    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now