Results 1 to 3 of 3

Thread: [RESOLVED] How to dynamically load and use a .NET dll

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2015
    Posts
    174

    Resolved [RESOLVED] How to dynamically load and use a .NET dll

    I have some dlls in my app folder. Each one contains 3 methods: methodA methodB methodC; of course the methods from one dll do stuff in different way that the others.
    Since I want to be able to add new dlls and use it without rebuild the app, I would like to store the dlls name in a db table, when app start I check if dlls listed in db exist, and show in in the program that this feature are available; then when the program need a specific one, I would load the selected dll(by the string result got from db query), and execute the methods.
    Can be done in vb.net?

  2. #2
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,958

    Re: How to dynamically load and use a .NET dll

    Quote Originally Posted by hannibal smith View Post
    I have some dlls in my app folder. Each one contains 3 methods: methodA methodB methodC; of course the methods from one dll do stuff in different way that the others.
    Since I want to be able to add new dlls and use it without rebuild the app, I would like to store the dlls name in a db table, when app start I check if dlls listed in db exist, and show in in the program that this feature are available; then when the program need a specific one, I would load the selected dll(by the string result got from db query), and execute the methods.
    Can be done in vb.net?
    This can certainly be done - you would need to use reflection for this though. If you want to really get into this then you might have a lot of reading to do.... However I have attached a very simple console app that shows how you can do this.

    The sample is made up of three projects.

    The Shared project defines a basic interface, IDemo, that is required for all plugins to implement and is referenced by the other two projects.

    The Plugin project is a simple console application that looks in a folder called "plugins" as a sub folder of the exe, finds any dlls and loads them, it loops through all the declared types, finds any that support the shared IDemo interface.

    The Lib1 project is a very basic example of a plugin.

    If you build the solution and copy the compiled Lib1.dll to a folder called "plugins" in the same folder as the pluin.exe you should be able to run the app and see what it does.
    Attached Files Attached Files

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2015
    Posts
    174

    Re: [RESOLVED] How to dynamically load and use a .NET dll

    Very useful Thanks!!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width