How to add a DLL Dynamically in c# RRS feed

  • Question

  • Hi,

    There is a Sage DLL which I have used in my c# windows application.

    The problem is that, whenever a new update comes for Sage, the DLL name will be changed.

    Like sgEngine230.dll  or sgEngine240.dll

    So Whenever there is update, we have to modify the c# code which is using this dll, and deploy the code once again.

    I would like to know if there is any way to load this DLL at runtime, so that I dont have to modify the code whenever there is new DLL available.

    Thanks in advance.


    Wednesday, February 20, 2019 2:28 PM

All replies

  • You can use System.Reflection.Assembly class. There is Load method which can load dll in runtime. Problem is that you cannot use types from this library. It could be solved by proxy or adapter pattern. 
    Wednesday, February 20, 2019 2:40 PM
  • Hello, 

    Answer is for an asked question:

    Assembly assembly = Assembly.LoadFile("my.dll");

    The rest you doing over loaded assembly.

    Most likely you also will need to read about Activator class to create an instance of the types available over assembly.GetTypes().

    Have noted - this is for .Net-based DLL's.

    Sincerely, Highly skilled coding monkey.

    Wednesday, February 20, 2019 2:42 PM
  • You can use Marshal.GetDelegateForFunctionPointer

    (with name of DLL in a .ini or other external location)

    Wednesday, February 20, 2019 3:59 PM
  • Perhaps in some cases you can use a fixed name for the DLL. When a new one is available, close the program and replace the DLL using the same name, maybe programmatically.

    Wednesday, February 20, 2019 6:19 PM
  • You're supposed to link to Sage 200 SDK (which is avaliable for use with .NET framework) instead of using native DLLs in the application directly.

    P.S.: When asking question about Sage softwares, be sure to include the numbers following it. Sage 50/100/200/300 are completely different products with different origins.
    Thursday, February 21, 2019 1:56 AM
  • Thanks a lot Cheong00

    The Sage Dll is sg50SdoEngine240.dll.

    Thursday, February 21, 2019 1:52 PM
  • I was also thinking of trying this way. Let me try to check if this will work. If so, then in future we will not have to modify the code and deploy. Just we will need to modify the DLL name. Thanks for giving the idea. 
    Thursday, February 21, 2019 1:53 PM
  • Hi RC15,

    Any update?

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Wednesday, February 27, 2019 6:22 AM